下载此文档

java课程设计-拼图游戏代码.doc


文档分类:IT计算机 | 页数:约6页 举报非法文档有奖
1/6
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/6 下载此文档
文档列表 文档介绍
package love; import .*; import ; import ; import ; import .*; public class Games extends JFrame implements ActionListener { private JButton buttons[][];// 存储按键的数组 private Container container;// 一个容器 private GridLayout layout;// 布局方式为 GridLayout private int count = 0, is[] = new int[8];// count 的作用是计算按键移动的次数, is[] 储存一个随机产生的 1到8 数字数组 public Games() { super(" 拼图游戏");// 设置标题 layout = new GridLayout(3, 3);// 3行3列 container = getContentPane();// 该容器的布局方式,及其重要,否则产生空引用异常 (layout);// 将该布局方式作用于容器 buttons = new JButton[3][3];// 给按键数组分配储存空间 int locate1, locate2;// locate1 用来指示当前产生的元素 locate2 用来指示 locate 1 之前的元素 for (locate1 = 0; locate1 < 8; locate1++) {// 该方法作用是产生 1到8这8 个数, 随机分配给数组,即无序排列 int g= new Random().nextInt(8) + 1;// 随机产生一个空白按键,即不显示的那个 is[locate1] = g; for (locate2 = locate1 - 1;0 <= locate2; locate2--) { if (is[locate1] == is[locate2]) break; } if (locate2 != -1) locate1--; } int temp = 0; int r= new Random().nextInt(3);// 随机产生一个 0到3 的数,代表空白按键的行 int l= new Random().nextInt(3);// 随机产生一个 0到3 的数,代表空白按键的列 for (int i= 0;i< 3; i++) { for (int j= 0;j< 3; j++) { if (r ==i &&l == j) {// 空白按键设置为 9 ,不显示 buttons[i][j] = new JButton("9"); (buttons[i][j]); buttons[i][j].setVisible(false); } else { buttons[i][j] = new JButton("" + is[temp++]);// 将数组数组的值作为显示的 8 个按键的名字 contai

java课程设计-拼图游戏代码 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数6
  • 收藏数0 收藏
  • 顶次数0
  • 上传人xxj16588
  • 文件大小0 KB
  • 时间2016-06-19
最近更新