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();
}
});
}
}

界面图,加入了背景音乐,引用自 https://blog.csdn.net/qq_40590018/article/details/81452392

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<Entry<String, String>> list) {
ranking = new String[5][2];
int i=0;
for(List.Entry<String, String> 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课程设计——俄罗斯方块的更多相关文章

  1. JAVA课程设计 俄罗斯方块

    俄罗斯方块 可实现功能 1.账号管理:登录.注册 2.游戏实现:移动.旋转.消除方块统计得分.暂停游戏.暂停后继续游戏.此轮游戏未结束开启新一轮游戏.游戏未结束退出游戏. 3.排行榜:按分数排名.按局 ...

  2. JAVA课程设计——俄罗斯方块(团队)

    1.团队介绍 1.1 团名:终于可以回家了嗷嗷嗷 1.2 团员介绍 2.参考来源 https://www.jb51.net/article/142716.htm 3.项目git地址 https://g ...

  3. java(课程设计之记事本界面部分代码公布)

    代码:涉及记事本的一些界面......!! /* *java课程设计之记事本(coder @Gxjun) * 编写一个记事本程序 * 要求: * 用图形用户界面实现. * 能实现编辑.保存.另存为.查 ...

  4. java课程设计(计算器)

    JAVA课程 设 计 报 告 1206401-18   瞿杰 一.设计时间 2013年6月 24日-----6月28日 二.设计地点 湖南城市学院实验楼计算机506机房 三.设计目的 1.巩固学习VB ...

  5. Java课程设计——博客作业教学数据分析系统(201521123084 林正晟)

    #课程设计--博客作业教学数据分析系统(201521123084 林正晟) 1.团队课程设计博客链接 博客作业教学数据分析系统 2.个人负责模块或任务说明 学生登陆界面的前端实现和与数据库的连接 学生 ...

  6. Java课程设计——博客作业教学数据分析系统(201521123082 黄华林)

    Java课程设计--博客作业教学数据分析系统(201521123082 黄华林) 一.团队课程设计博客链接 博客作业教学数据分析系统(From:网络五条狗) 二.个人负责模块或任务说明 1.网络爬虫 ...

  7. java课程设计--We Talk(201521123061)

    java课程设计--We Talk(201521123061) 团队博客链接:http://www.cnblogs.com/slickghost/ 数据库 一.通过Dao模式建立与数据库的连接 1.数 ...

  8. Java 课程设计 "Give it up"小游戏(团队)

    JAVA课程设计 "永不言弃"小游戏(From :Niverse) 通过Swing技术创建游戏的登陆注册界面,使用mySQL数据库技术完成用户的各项信息保存和游戏完成后的成绩保存. ...

  9. Java课程设计----仿Windows标准型计算器

    JAVA课程设计 仿Windows标准型计算器(By Yanboooooooo) 一.团队介绍: 连燕波[组长]:网络1513学生. 张文博[组员]:网络1513学生. 二.项目git地址 码云项目地 ...

随机推荐

  1. python中pandas数据分析基础3(数据索引、数据分组与分组运算、数据离散化、数据合并)

    //2019.07.19/20 python中pandas数据分析基础(数据重塑与轴向转化.数据分组与分组运算.离散化处理.多数据文件合并操作) 3.1 数据重塑与轴向转换1.层次化索引使得一个轴上拥 ...

  2. 解决oracle 11g 导出空表的方法

    ORACLE 11G中有个新特性,当表无数据时,不分配segment,以节省空间. 解决方法: 1)insert一行,再rollback就产生segment了 该方法是在在空表中插入数据,再删除,则产 ...

  3. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-backward

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  4. WEB前段(HTML+JS),后端(MYSQL+PHP)开发基础

    一.HTML HTML:超文本标记语言,可以加载JS/CSS/图片/链接等非文字的内容 一切的网页开发技术都需要建立在HTML的基础之上 HTML的结构和语法 HTML元素 注释:  <!-- ...

  5. POJ 1458:Common Subsequence

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 41957   Accepted: 16 ...

  6. Day4-T2

    原题目 某大厦共有 N 层,现在知道共有 K 个请求要上下电梯:下面告诉你每个请求乘电梯的出发层次和结 束层次.请你求出整个电梯的运行过程.假设电梯一开始停在第一层,运行 K 个请求最后回到第一层. ...

  7. jQuery获取display为none的隐藏元素的宽度和高度的解决方案

    1.利用给元素添加行内样式:visibility:hidden;display:block 2.让隐藏元素变成有物理尺寸存在,但不可见,获取元素宽高 3.再给它还原成display为none,去除vi ...

  8. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-text-width

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  9. Git的http与ssh配置

    http 进入git bash 直接clone所需项目 通过http方式 eg:git clone http://xxxxxxxxxx/bk_linux_inspect-master.git 会弹出提 ...

  10. 中国移动携手华为百度展示5G应用,实现8K视频传输

    在今日举行的 2019 年百度云智峰会上,中国移动携手华为和百度,首次展示基于 SA 架构的 5G Vertical LAN (行业局域网)技术,承载 8K 实时会议系统,助力企业云办公.该技术可为合 ...