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;/*** @author TongShuHao* @date 2020年7月17日 * @version 1.0  * Description: */
public class DFirstGUI extends JPanel implements ActionListener{/*** */private static final long serialVersionUID = 1L;// 1.声明要用到 的容器/组件(声明变量)private JPanel north, center;private JLabel mima;private JPasswordField passwordField;private JScrollBar bar;private JTextArea jTextArea;// 2.初始化主容器并设置基本属性,并调用初始化方法,添加组件public DFirstGUI() {this.setLayout(new BorderLayout());initComponent();}// 3.初始化组件private void initComponent() {// 3.1创建容器/组件north = new JPanel();center = new JPanel();mima = new JLabel("密码");passwordField = new JPasswordField(10);/*JRadioButton sex1 = new JRadioButton("男");JRadioButton sex2 = new JRadioButton("女");bg.add(sex1);bg.add(sex2);*/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                      点击登陆键即可进入游戏");// 3.2设置容器布局管理器north.setLayout(new FlowLayout());// 3.3把组件依次放到对应容器中north.setLayout(new FlowLayout());/*north.add(sex1,FlowLayout());north.add(sex2,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);// 3.4给组件添加事件监听器}// 4.事件处理@Overridepublic void actionPerformed(ActionEvent e) {}// 5.main方法,创建对象,完成界面初始化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;/*** @author TongShuHao* @date 2020年7月17日 * @version 1.0  * Description: 继承了JFrame,那么DMainGUI可以看作一个窗口类*               实现了ActionListener,那么可以看作是一个事件监听器*/
public class DMainGUI extends JFrame implements ActionListener{/*** */private static final long serialVersionUID = 1L;//1.声明要用到 的容器/组件(声明变量)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;//2.初始化主容器并设置基本属性,并调用初始化方法,添加组件public DMainGUI() {// TODO Auto-generated constructor stub// 得到屏幕的宽高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);//调用initComponent,初始化其他组件this.initComponent();//设置窗口是否可见this.setVisible(true);}//3.初始化组件private void initComponent(){//3.1创建容器/组件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("游戏说明");//3.2设置容器布局管理器north.setLayout(new FlowLayout());center.setLayout(new CardLayout());//3.3把组件依次放到对应容器中 north.add(nichen);north.add(jTextField);north.add(jButton);north.add(jComboBox);/*center.add(mima);center.add(passwordField);*/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);//3.4给组件添加事件监听器jButton.addActionListener(this);jComboBox.addActionListener(this);}//4.事件处理@Overridepublic 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) {//System.out.println("游戏界面");((CardLayout)center.getLayout()).show(center,"0");}else if (index == 1) {//System.out.println("得分界面");((CardLayout)center.getLayout()).show(center,"1");}}}//5.main方法,创建对象,完成界面初始化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;/*** @author TongShuHao* @date 2020年7月17日 * @version 1.0  * Description: 继承了JFrame,那么DMainGUI可以看作一个窗口类*               实现了ActionListener,那么可以看作是一个事件监听器*/
public class DMainGUI extends JFrame implements ActionListener{/*** */private static final long serialVersionUID = 1L;//1.声明要用到 的容器/组件(声明变量)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;//2.初始化主容器并设置基本属性,并调用初始化方法,添加组件public DMainGUI() {// TODO Auto-generated constructor stub// 得到屏幕的宽高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);//调用initComponent,初始化其他组件this.initComponent();//设置窗口是否可见this.setVisible(true);}//3.初始化组件private void initComponent(){//3.1创建容器/组件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("游戏说明");//3.2设置容器布局管理器north.setLayout(new FlowLayout());center.setLayout(new CardLayout());//3.3把组件依次放到对应容器中 north.add(nichen);north.add(jTextField);north.add(jButton);north.add(jComboBox);/*center.add(mima);center.add(passwordField);*/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);//3.4给组件添加事件监听器jButton.addActionListener(this);jComboBox.addActionListener(this);}//4.事件处理@Overridepublic 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) {//System.out.println("游戏界面");((CardLayout)center.getLayout()).show(center,"0");}else if (index == 1) {//System.out.println("得分界面");((CardLayout)center.getLayout()).show(center,"1");}}}//5.main方法,创建对象,完成界面初始化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;/*** @author TongShuHao* @date 2020年7月17日* @version 1.0 Description:*/
public class DRecordGUI extends JPanel implements ActionListener {/*** */private static final long serialVersionUID = 1L;// 1.声明要用到 的容器/组件(声明变量)private JPanel north, center;private JTextArea jTextArea;// 2.初始化主容器并设置基本属性,并调用初始化方法,添加组件public DRecordGUI() {this.setLayout(new BorderLayout());initComponent();}// 3.初始化组件private void initComponent() {// 3.1创建容器/组件north = new JPanel();center = new JPanel();/*fenge = new JLabel("|");selfBtn = new JButton("个人");allBtn = new JButton("总榜");level = new JComboBox<>();level.addItem("初级");level.addItem("中级");level.addItem("高级");*/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小时内帮您解决");// 3.2设置容器布局管理器north.setLayout(new FlowLayout());// 3.3把组件依次放到对应容器中north.setLayout(new FlowLayout());/*north.add(level);north.add(selfBtn);north.add(fenge);north.add(allBtn);*/center.setLayout(new BorderLayout());center.add(jTextArea, BorderLayout.CENTER);this.add(center, BorderLayout.CENTER);this.add(north, BorderLayout.NORTH);// 3.4给组件添加事件监听器}// 4.事件处理@Overridepublic void actionPerformed(ActionEvent e) {}// 5.main方法,创建对象,完成界面初始化public static void main(String[] args) {new DRecordGUI();}}

whack-a-mole(打地鼠)相关推荐

  1. 2DToolkit官方文档中文版打地鼠教程(一):初始设置

    这是2DToolkit官方文档中 Whack a Mole 打地鼠教程的译文,为了减少文中过多重复操作的翻译,以及一些无必要的句子,这里我假设你有Unity的基础知识(例如了解如何新建Sprite等) ...

  2. Python 打地鼠小游戏

    对于打地鼠游戏需要有一个清晰的逻辑思路,当然要制作打地鼠游戏还需要在Python中导入背景图片.地鼠图片等等.好了我们废话不多说,直接上代码. class GameManager:def __init ...

  3. python小游戏打地鼠下载_Python 打地鼠小游戏

    对于打地鼠游戏需要有一个清晰的逻辑思路,当然要制作打地鼠游戏还需要在Python中导入背景图片.地鼠图片等等.好了我们废话不多说,直接上代码. class GameManager: def __ini ...

  4. JavaScript - WebAPI - 案例 - 点名系统/打地鼠/计时器/今日代办

    点名系统 <!DOCTYPE html> <html><head><meta charset="UTF-8"><title&g ...

  5. 自学 cocos2d 游戏开发应该按什么步骤进行?

     著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:孙鹏飞 链接:http://www.zhihu.com/question/21114802/answer/22840 ...

  6. 非常优秀的iphone学习文章总结!

    This site contains a ton of fun tutorials – so many that they were becoming hard to find! So I put t ...

  7. Unity插件-2D TOOLKIT入门-打鼹鼠教程

    打鼹鼠(Whack a Mole Tutorial) 创建游戏对象 记得经常保存你的场景! Camera 注意:如果您需要有关创建相机的更多详细信息,请点击此处 删除默认的Unity camera - ...

  8. (译)如何使用cocos2d来制作一个打地鼠的游戏:第一部分

    免责申明(必读!):本博客提供的所有教程的翻译原稿均来自于互联网,仅供学习交流之用,切勿进行商业传播.同时,转载时不要移除本申明.如产生任何纠纷,均与本博客所有人.发表该翻译稿之人无任何关系.谢谢合作 ...

  9. Python小游戏(打地鼠)

    源码分享: import cfg import sys import pygame import random from modules import *'''游戏初始化''' def initGam ...

  10. 如何用python制作五子棋游戏_Python制作打地鼠小游戏

    原文链接 Python制作小游戏(二十一)​mp.weixin.qq.com 效果展示 打地鼠小游戏https://www.zhihu.com/video/1200492442610450432 简介 ...

最新文章

  1. 浮点数 IEEE表示 舍入 运算
  2. apache nginx mysql php_php+Apache2+Nginx+Mysql
  3. 大数据量下的sort
  4. 整理的一些比较基础的面试知识点
  5. 【模板】在build中配置resources来防止我们资源导出失败的问题
  6. Ubuntu18.04.4 环境下对属性加密算法CP-ABE环境搭建
  7. python常用包有哪些品牌_python 常用包总结
  8. 怎么用c语言输入一串字符个数字,请问这个用c怎么做:输入一串字符,分别统计其中数字和字母的个数...
  9. Python 操作 mongodb 数据库
  10. Lady Gaga Feat. Colby O'Donis - Just Dance
  11. 模拟Post登陆带验证码的网站
  12. 花生壳内网穿透实践指南
  13. 计算机办公自动化试题及答案,计算机等级考试,办公自动化考试试题(三)
  14. 模拟QQ上面的导航按钮
  15. laravel响应速度慢
  16. 解决win10中无法打开CHM文件的方法
  17. PWR-低功耗模式-STM32F4
  18. PySpark RDD操作
  19. MaxEnt运行报错的各种问题及解决方法
  20. Inserting Videos into Videos_论文阅读

热门文章

  1. Linux | 相关操作
  2. 魔兽世界怀旧服服务器平衡状态,魔兽世界怀旧服阵营最平衡服务器“灰烬使者”,引大量工作室入驻...
  3. 从零开始搭建一个语音对话机器人
  4. oracle 11.1.0.7.24,11g Patchset 1 11.1.0.7 For Linux发布
  5. Science:中国农业科学院作物科学研究所周文彬团队在水稻中发现单一基因可使水稻显著增产...
  6. 多线程中的可见性问题
  7. 社会性动物 第五章:大众传播、宣传与说服
  8. 计算机型号cpu主频,电脑cpu型号怎么看好不好 教你看cpu主频等详细性能参数
  9. 手机连接amazon虚拟机服务器,亚马逊EC2可直接导入VMware虚拟机镜像
  10. 戴尔win10插耳机还外放_联想小新,win10系统,外放声音嘶哑,用耳机正常,现已找到解决办法,希望对面临同样困扰的朋友有所帮助!...