DFirstGUI.java 首页
package com.bigdata.whack;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollBar;
import javax.swing.JTextArea;
public class DFirstGUI extends JPanel implements ActionListener{
private static final long serialVersionUID = 1L;
private JPanel north, center;
private JLabel mima;
private JPasswordField passwordField;
private JScrollBar bar;
private JTextArea jTextArea;
public DFirstGUI() {
this.setLayout(new BorderLayout());
initComponent();
}
private void initComponent() {
north = new JPanel();
center = new JPanel();
mima = new JLabel("密码");
passwordField = new JPasswordField(10);
bar = new JScrollBar(JScrollBar.HORIZONTAL);
bar.setPreferredSize(new Dimension(120, 20));
bar.setMinimum(0);
bar.setMaximum(100);
bar.setValue(80);
jTextArea = new JTextArea();
jTextArea.setEditable(false);
Font x = new Font("Serif",0,20);
jTextArea.setFont(x);
jTextArea.setText("\n\n 欢迎来到打地鼠游戏\n\n\n\n 制作人:大数据1901班童书浩 \n\n\n\n\n 点击登陆键即可进入游戏");
north.setLayout(new FlowLayout());
north.setLayout(new FlowLayout());
center.setLayout(new FlowLayout());
center.add(mima);
center.add(passwordField);
center.add(bar);
center.add(jTextArea, new FlowLayout());
this.add(center, BorderLayout.CENTER);
this.add(north, BorderLayout.NORTH);
}
@Override
public void actionPerformed(ActionEvent e) {
}
public static void main(String[] args) {
new DFirstGUI();
}
}
DGameGUI.java游戏界面
package com.bigdata.whack;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.bigdata.whack.DGameGUI;
public class DMainGUI extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
public static String user_name = "匿名玩家";
private JPanel north,center,blank;
private JLabel nichen;
@SuppressWarnings("unused")
private JLabel mima;
private JTextField jTextField;
@SuppressWarnings("unused")
private JPasswordField passwordField;
private JButton jButton;
private JComboBox<String> jComboBox;
private DGameGUI dGameGUI;
private DRecordGUI dRecordGUI;
private DFirstGUI dFirstGUI;
public DMainGUI() {
int screenWidh = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
int screenHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
this.setTitle("打地鼠");
this.setSize(500, 500);
this.setLocation((screenWidh - this.getWidth()) / 2, (screenHeight - this.getHeight()) / 2);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.initComponent();
this.setVisible(true);
}
private void initComponent(){
blank = new JPanel();
north = new JPanel();
center = new JPanel();
dGameGUI = new DGameGUI();
dRecordGUI = new DRecordGUI();
dFirstGUI = new DFirstGUI();
nichen = new JLabel("玩家昵称");
mima = new JLabel("密码");
jTextField = new JTextField(10);
passwordField = new JPasswordField(10);
jButton = new JButton("登陆");
jComboBox = new JComboBox<>();
jComboBox.addItem("玩游戏");
jComboBox.addItem("游戏说明");
north.setLayout(new FlowLayout());
center.setLayout(new CardLayout());
north.add(nichen);
north.add(jTextField);
north.add(jButton);
north.add(jComboBox);
center.add("0",dGameGUI);
center.add("1",dRecordGUI);
center.add("2",blank);
center.add("3",dFirstGUI);
((CardLayout)center.getLayout()).show(center,"3");
this.add(center,BorderLayout.CENTER);
this.add(north,BorderLayout.NORTH);
jButton.addActionListener(this);
jComboBox.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if(source == jButton){
jTextField.setText(user_name);
jTextField.setEditable(false);
jButton.setEnabled(false);
jComboBox.setEnabled(true);
((CardLayout)center.getLayout()).show(center,"0");
}else if(source == jComboBox){
int index = jComboBox.getSelectedIndex();
if (index == 0) {
((CardLayout)center.getLayout()).show(center,"0");
}else if (index == 1) {
((CardLayout)center.getLayout()).show(center,"1");
}
}
}
public static void main(String[] args) {
new DMainGUI();
}
}
DMainGUI.java登陆界面
package com.bigdata.whack;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.bigdata.whack.DGameGUI;
public class DMainGUI extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
public static String user_name = "匿名玩家";
private JPanel north,center,blank;
private JLabel nichen;
@SuppressWarnings("unused")
private JLabel mima;
private JTextField jTextField;
@SuppressWarnings("unused")
private JPasswordField passwordField;
private JButton jButton;
private JComboBox<String> jComboBox;
private DGameGUI dGameGUI;
private DRecordGUI dRecordGUI;
private DFirstGUI dFirstGUI;
public DMainGUI() {
int screenWidh = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
int screenHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
this.setTitle("打地鼠");
this.setSize(500, 500);
this.setLocation((screenWidh - this.getWidth()) / 2, (screenHeight - this.getHeight()) / 2);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.initComponent();
this.setVisible(true);
}
private void initComponent(){
blank = new JPanel();
north = new JPanel();
center = new JPanel();
dGameGUI = new DGameGUI();
dRecordGUI = new DRecordGUI();
dFirstGUI = new DFirstGUI();
nichen = new JLabel("玩家昵称");
mima = new JLabel("密码");
jTextField = new JTextField(10);
passwordField = new JPasswordField(10);
jButton = new JButton("登陆");
jComboBox = new JComboBox<>();
jComboBox.addItem("玩游戏");
jComboBox.addItem("游戏说明");
north.setLayout(new FlowLayout());
center.setLayout(new CardLayout());
north.add(nichen);
north.add(jTextField);
north.add(jButton);
north.add(jComboBox);
center.add("0",dGameGUI);
center.add("1",dRecordGUI);
center.add("2",blank);
center.add("3",dFirstGUI);
((CardLayout)center.getLayout()).show(center,"3");
this.add(center,BorderLayout.CENTER);
this.add(north,BorderLayout.NORTH);
jButton.addActionListener(this);
jComboBox.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if(source == jButton){
jTextField.setText(user_name);
jTextField.setEditable(false);
jButton.setEnabled(false);
jComboBox.setEnabled(true);
((CardLayout)center.getLayout()).show(center,"0");
}else if(source == jComboBox){
int index = jComboBox.getSelectedIndex();
if (index == 0) {
((CardLayout)center.getLayout()).show(center,"0");
}else if (index == 1) {
((CardLayout)center.getLayout()).show(center,"1");
}
}
}
public static void main(String[] args) {
new DMainGUI();
}
}
DRecordGUI.java记录查看界面
package com.bigdata.whack;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class DRecordGUI extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L;
private JPanel north, center;
private JTextArea jTextArea;
public DRecordGUI() {
this.setLayout(new BorderLayout());
initComponent();
}
private void initComponent() {
north = new JPanel();
center = new JPanel();
jTextArea = new JTextArea();
jTextArea.setEditable(false);
Font x = new Font("Serif", 0, 20);
jTextArea.setFont(x);
jTextArea.setText("\n "
+ "打地鼠\n\n 欢迎来到打地鼠游戏!该游戏是一款锻炼反应能\n 力的游戏,"
+ "游戏面向全年龄段的玩家,在进行游戏过\n 程中体验用鼠标进行快速点击地鼠进行加分。游戏分\n "
+ "为初级、中级、高级三个等级可供不同年龄段的玩家\n 选择,在游戏中体验高度集中"
+ "的快乐时刻!\n\n\n\n 如果发现技术原因导致无法运行\n "
+ " 请电话联系:18855428512\n 技术人员将在24小时内帮您解决");
north.setLayout(new FlowLayout());
north.setLayout(new FlowLayout());
center.setLayout(new BorderLayout());
center.add(jTextArea, BorderLayout.CENTER);
this.add(center, BorderLayout.CENTER);
this.add(north, BorderLayout.NORTH);
}
@Override
public void actionPerformed(ActionEvent e) {
}
public static void main(String[] args) {
new DRecordGUI();
}
}