import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Hua_Rong_Road extends JFrame implements MouseListener,KeyListener,ActionListener {
private static final int ERROR_MESSAGE = 0;
private static final int WARNING_MESSAGE = 0;
int cnt=0;
Persion person[]=new Persion[10];//定义一个十个人的数组,
//定义按钮按钮
JButton left,right,above,below;
JButton restart=new JButton("重新开始");
JButton about=new JButton("游戏背景");
JButton help=new JButton("游戏帮助");
JButton mouse=new JButton("鼠标操作");
JButton key=new JButton("键盘操作");
JButton message=new JButton("当前步数:"+cnt);
JButton begin=new JButton("开始游戏");
JButton star=new JButton();
//定义数组,用来放各种人物形象。
String name[]={"曹操","关羽","张飞","黄忠","马超","赵云","兵","兵","兵","兵"};
public Hua_Rong_Road(){
//JOptionPane.showMessageDialog(this, "开始游戏前,请先阅读下方的游戏帮助,游戏背景可自行了解.");
init();
//定义窗体的各种参数如大小位置,可见与否等。
//setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(200,200,640,800);//设置窗体初始位置以及大小的一个函数
setVisible(true);//窗口可见
//person[9].requestFocus();//获取焦点需要卸载setVisible后面才行
validate();//使用validate方法是容器再次布置其组件,确保布局有效
}
//初始化,在容器中加入按钮等工具
public void init(){
setLayout(null);
message.setBackground(Color.ORANGE);
//定义重新开始按钮,大小,位置和监听器事件。
add(restart);
restart.setBounds(120, 640, 100, 50);
//restart.setBackground(Color.RED);
restart.addActionListener(this);
//定义游戏帮助按钮,大小,位置和监听器事件。
add(about);
about.addActionListener(this);
about.setBounds(250,640,100,50);
//定义鼠标操作按钮,大小,位置和监听器事件。
add(mouse);
mouse.setBounds(280,40,100,50);
mouse.addActionListener(this);
//定义键盘操作按钮,大小,位置和监听器事件。
add(key);
key.setBounds(400, 40, 100, 50);
key.addActionListener(this);
//定义 游戏帮助按钮,大小,位置和监听器事件。
add(help);
help.setBounds(380, 640, 100, 50);
help.addActionListener(this);
//定义游戏背景,大小,位置和监听器事件。
add(message);
message.setBounds(110,40,160,50);
ImageIcon starr=new ImageIcon("F:\\MYJAVA\\Myprogram\\HUARongd\\src\\MYHRD\\HRD.gif");//导入图片
star.setIcon(starr);
star.setBounds(108,208,400,4
Java 小游戏之华容道
最新推荐文章于 2021-02-16 03:38:40 发布
本文介绍了使用Java编程实现经典益智游戏华容道的详细过程,包括游戏规则的解析、棋盘的设计、滑动块的逻辑处理以及用户交互功能的实现。通过实例代码讲解如何运用Java进行游戏开发,提升编程技巧。
摘要由CSDN通过智能技术生成