java课程设计俄罗斯方块_JAVA课程设计——俄罗斯方块
###0.负责模块为可视化界面,技术栈为 (1)异常处理 (2)多线程 (3)文件存储 (4)Java swing ###1.登陆界面 ####我的代码 import java.awt.Color; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; import tetris.control.*;
/**
*
* @author lsm
*
*/
public class Main {
private static void login() {
JFrame frame = new JFrame();
frame.setResizable(false);
ImageIcon background = new ImageIcon("beautify/login.jpg");
JLabel backLabel = new JLabel(background);
backLabel.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());
JPanel panel = new JPanel();
panel = (JPanel) frame.getContentPane();
panel.setOpaque(false);
panel.setLayout(new FlowLayout());
frame.getLayeredPane().add(backLabel, new Integer(Integer.MIN_VALUE));
/*设置界面属性*/
frame.setTitle("Tetris");
GridLayout grid = new GridLayout(2, 2);
grid.setHgap(25);
grid.setVgap(25);
JPanel panel1 = new JPanel(grid);
panel1.setOpaque(false);
Font f1 = new Font("Serif", Font.BOLD, 27);
Font f2 = new Font("Serif", Font.ITALIC, 47);
JTextField b1 = new JTextField(10);
JPasswordField b2 = new JPasswordField(10);
JLabel label1 = new JLabel(" Player Name");
JLabel label2 = new JLabel(" Password");
JLabel label3 = new JLabel("Welcome to Tetris!");
label1.setFont(f1);
label2.setFont(f1);
label3.setFont(f2);
panel1.add(label1);
panel1.add(b1);
panel1.add(label2);
panel1.add(b2);
JPanel panel2 = new JPanel();
panel2.setOpaque(false);
JButton button1 = new JButton("Login");
JButton button2 = new JButton("Register");
button1.setForeground(Color.BLACK);
button2.setForeground(Color.BLACK);
button1.setBackground(Color.lightGray);
button2.setBackground(Color.lightGray);
panel2.add(button1);
panel2.add(button2);
panel.add(panel1);
panel.add(panel2);
panel.add(label3);
frame.setBounds(100, 100, background.getIconWidth(), background.getIconHeight());
frame.setLocation(450, 60);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);
button1.addActionListener(new ActionListener() {
@SuppressWarnings("deprecation")
@Override
public void actionPerformed(ActionEvent arg0) {
String playerName = b1.getText();
String playerPassword = b2.getText();
try {
if (PlayerFile.matchPassword(playerName, playerPassword)) {
frame.setVisible(false);
new RussiaBlocksGame("Tetris");
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
String playerName = b1.getText();
@SuppressWarnings("deprecation")
String playerPassword = b2.getText();
try {
if (!PlayerFile.writeFile(playerName, playerPassword)) {
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Music();
login();
}
});
}
}
###2.游戏界面 ####我的代码(这里就贴主要界面代码,具体方法不展示) public class RussiaBlocksGame extends JFrame { private GameCanvas canvas; private ErsBlock block; private boolean playing = false; private ControlPanel ctrlPanel; private JMenuBar menuBar = new JMenuBar(); private JMenu help = new JMenu("Help"); private JMenu setting = new JMenu("Setting"); private JMenuItem about = new JMenuItem("About"); private JMenuItem setBackground = new JMenuItem("SetBackground"); private JMenuItem setFrontground = new JMenuItem("SetFrontground"); private JMenuItem chart=new JMenuItem("Ranking List");
/*
* 初始化菜单栏
*/
private void initScope() {
setJMenuBar(menuBar);
menuBar.add(help);
menuBar.add(setting);
help.add(about);
help.add(chart);
setting.add(setBackground);
setting.add(setFrontground);
/*
* 设置自定义颜色,引用自 https://www.jb51.net/article/142716.htm
*/
setFrontground.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Color newFrontColor = JColorChooser.showDialog(RussiaBlocksGame.this, "SetFrontground", canvas.getBlockColor());
if (newFrontColor != null) {
canvas.setBlockColor(newFrontColor);
}
}
});
setBackground.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Color newBackColor = JColorChooser.showDialog(RussiaBlocksGame.this, "SetBackground",
canvas.getBackgroundColor());
if (newBackColor != null) {
canvas.setBackgroundColor(newBackColor);
}
}
});
about.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"→ move right " + "← move left " + "↓ speed up " + "↑ conservasion");
}
});
chart.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
new RanklistDialog(PlayerFile.outputCharts());
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
}
public RussiaBlocksGame(String title) {
super(title);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(450, 570);
setLocation(450, 60);
setTitle("Tetris");
initScope();
Container container = getContentPane();
container.setLayout(new BorderLayout(6, 0));
canvas = new GameCanvas(ROWS, COLS);
ctrlPanel = new ControlPanel( this );
container.add(canvas, BorderLayout.CENTER);
container.add(ctrlPanel, BorderLayout.EAST);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
stopGame();
System.exit(0);
}
});
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent ce) {
canvas.adjust();
}
});
setVisible(true);
setResizable(false);
}
}
游戏界面为
###3.排行榜(只取前五名) ####我的代码: import java.awt.Color; import java.awt.Font; import java.util.HashMap; import java.util.Map; import javax.swing.ImageIcon; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel;
public class RanklistDialog extends JDialog{
private JLabel score1,score2,score3,score4,score5;
private JLabel name1,name2,name3,name4,name5;
private String[][] ranking;
public RanklistDialog(List> list) {
ranking = new String[5][2];
int i=0;
for(List.Entry e: list.entrySet()) {
String name=e.getKey();
String score=e.getValue();
ranking[i][0]=name;
ranking[i][1]=score;
i++;
}
Font f = new Font("Serif", Font.ITALIC, 25);
name1 = new JLabel();
name1.setText(ranking[0][0]);
name1.setFont(f);
name1.setForeground(Color.yellow);
name1.setBounds(150,270, 100, 30);
this.add(name1);
score1 = new JLabel();
score1.setText(ranking[0][1]);
score1.setFont(f);
score1.setForeground(Color.yellow);
score1.setBounds(280,270,100, 30);
this.add(score1);
name2 = new JLabel();
name2.setText(ranking[1][0]);
name2.setFont(f);
name2.setForeground(Color.yellow);
name2.setBounds(150,330,100, 30);
this.add(name2);
score2 = new JLabel(ranking[1][1]);
score2.setFont(f);
score2.setForeground(Color.yellow);
score2.setBounds(280,330,100, 30);
this.add(score2);
name3 = new JLabel();
name3.setText(ranking[2][0]);
name3.setFont(f);
name3.setForeground(Color.yellow);
name3.setBounds(150, 390, 100, 30);
this.add(name3);
score3 = new JLabel(ranking[2][1]);
score3.setFont(f);
score3.setForeground(Color.yellow);
score3.setBounds(280, 390, 100, 30);
this.add(score3);
name4 = new JLabel();
name4.setText(ranking[3][0]);
name4.setFont(f);
name4.setForeground(Color.yellow);
name4.setBounds(150, 450, 100, 30);
this.add(name4);
score4 = new JLabel(ranking[3][1]);
score4.setFont(f);
score4.setForeground(Color.yellow);
score4.setBounds(280, 450, 100, 30);
this.add(score4);
name5 = new JLabel();
name5.setText(ranking[4][0]);
name5.setFont(f);
name5.setForeground(Color.yellow);
name5.setBounds(150, 510, 100, 30);
this.add(name5);
score5 = new JLabel(ranking[4][1]);
score5.setFont(f);
score5.setForeground(Color.yellow);
score5.setBounds(280, 510, 100, 30);
this.add(score5);
ImageIcon icon = new ImageIcon("beautify/charts.jpg");
JLabel background = new JLabel(icon);
background.setBounds(0, 0, icon.getIconWidth(),icon.getIconHeight());
JPanel imagePanel = (JPanel)this.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(null);
this.setModal(true);
this.setTitle("Ranking List");
this.setLayout(null);
this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
this.setResizable(false);
this.setSize(400, 600);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}
}
排行榜界面(好像要暴露什么)
###4.我的总结 对于一个喜欢美术的人来说,界面设计真的是爽歪歪啊~,不过好像效果一般啊。。。一直对代码这块比较抵触,开发也不是以后的发展方向, ,这次课程设计这个模块就主要是整合另外两个成员写的方法,难度小,乐在其中。
java课程设计俄罗斯方块_JAVA课程设计——俄罗斯方块相关推荐
- java 公交管理系统 代码_JAVA课程设计报告公交管理系统.pdf
Java期末课程设计 -- Busmanagerment 课程名称:算法设计与分析 任课老师:吴倩 学生姓名:谢秀华 学生学号:1037005 所在院系:信息工程学院 班级: 10计算机1班 一.前言 ...
- java课程设计日历_java课程设计日历记事本赵锐.doc
java课程设计日历记事本赵锐.doc 2本科生课程设计课程名称JAVA程序设计课程设计题目日历记事本学号201440930252学生姓名赵锐所在专业2014计算机学院所在班级信工2班成绩课程设计时间 ...
- java多功能计算器_Java课程设计多功能计算器 PDF 下载
1.摘要: 为复习巩固Java语言的基础知识,进一步加深对java语言的理解和掌控.同过本课程设计使自身能够全面的掌握面向对象程序设计的有关概念和开发方法,以便能较全面地理解.掌握和综合运用所学的知识 ...
- java课程设计培训班_Java课程设计
课程设计--博客作业五子棋(201521123009 张晨晨) •团队课程设计博客链接 •个人负责模块或任务说明 五子棋的绘制 棋盘的绘制 重新开始功能的实现 悔棋功能的实现 •自己的代码提交记录截图 ...
- java 课程设计 计算器_JAVA课程设计-计算器(201521123028 李家俊)
1.团队课程设计博客链接 2.个人负责模板或任务说明 主要负责计算器图形界面 包括操作按钮,菜单项以及输出面板的设计 3.自己的代码提交记录截图 4.自己负责模块或任务详细说明 代码分析: 主类中有如 ...
- java飞机大战流程图_JAVA课程设计-飞机大战
JAVA课程设计-飞机大战 1.团队名称.团队成员介绍 1.1 团队名称:做个飞机哦 1.2团队成员介绍: 余俊良(组长):编写博客.游戏主界面设计与实现.英雄机与子弹类的实现.场景设计 林祥涛:游戏 ...
- java课程设计 成绩_Java课程设计—学生成绩管理系统(201521123004-林艺如)
1.团队课程设计博客 2.个人负责模块或任务说明 ①.Menu Menu.jsp 在页面中给出提示,用HTML的,与下一个跳转页面进行连接,即点击后进入下一个页面 MenuTeacher.jsp 利用 ...
- java课设 五子棋_Java课程设计 ————五子棋 (个人博客)
JAVA课程设计 五子棋(博客个人版) •团队课程设计博客链接 •个人负责模块或任务说明 1.主框架类:设置棋盘窗体,颜色等 2.isWin方法:判断胜负 •自己的代码提交记录截图 •自己负责模块或任 ...
- java课程设计象棋_java课程设计 中国象棋
[实例简介] 内附eclipse项目,可运行jar包,和课程设计报告,觉得让你一下子看懂 [实例截图] [核心代码] P17-象棋java课程设计 └── P17-象棋java课程设计 ├── res ...
最新文章
- CALayer 一些简单的小例子
- 菜鸟学Linux 第052篇笔记 httpd-install and section2
- ubuntu配置java_Ubuntu 16.04下Java环境安装与配置
- Linux一些经典书籍
- Verilog HDL 学习笔记3-Latch
- 惠斯通电桥信号调理芯片_变频器通电后无反应,如何检查维修?
- (转)金融“核武器”即将引爆整个行业
- 一个方便快捷gif在线水印制作(支持文字和图片)
- Silvaco TCAD安装包相关问题
- windows局域网的一个经典的入侵方法
- ArcGIS使用(二)ArcGIS加载天地图
- 这一年又是稀里糊涂地度过了
- ssd硬盘 速度慢 linux,Linux 对SSD硬盘优化的方法
- SCSS迷你书(上)
- JZOJ 5602. 【NOI2018模拟3.26】Cti
- in-place运算总结
- 我所理解的技术领导力
- access求斐波拉契数列_access函数_清华编程高手尹成带你实战C/C++编程_C/C++/C#视频-51CTO学院...
- 计算机网络技术专业论文选题有哪些,计算机网络技术专业论文参考选题大全(125个)...
- More Exceptional C++