为了账号安全,请及时绑定邮箱和手机立即绑定

2048的一段代码,求解答?

2048的一段代码,求解答?

cyc川 2017-03-07 15:48:28
 static JLabel jLabel2 = new JLabel((Icon) new ImageIcon("2.png")); static JLabel jLabel4 = new JLabel((Icon) new ImageIcon("4.png")); static JLabel jLabel8 = new JLabel((Icon) new ImageIcon("8.png")); static JLabel jLabel16 = new JLabel((Icon) new ImageIcon("16.png")); static JLabel jLabel32 = new JLabel((Icon) new ImageIcon("32.png")); static JLabel jLabel64 = new JLabel((Icon) new ImageIcon("64.png")); static JLabel jLabel128 = new JLabel((Icon) new ImageIcon("128.png")); static JLabel jLabel256 = new JLabel((Icon) new ImageIcon("256.png")); static JLabel jLabel512 = new JLabel((Icon) new ImageIcon("512.png")); static JLabel jLabel1024 = new JLabel((Icon) new ImageIcon("1024.png")); static JLabel jLabel2048 = new JLabel((Icon) new ImageIcon("2048.png")); static JLabel jLabel1 = new JLabel((Icon) new ImageIcon("1.png")); static JLabel jLabel0 = new JLabel((Icon) new ImageIcon("bj.png")); static JLabel im = null; private Panel panel1 = new Panel(); public static JLabel Image(int i) {  if (i == 2) {       im = jLabel2;  } else if (i == 4) {       im = jLabel4;  } else if (i == 8) {       im = jLabel8;  } else if (i == 16) {       im = jLabel16;  } else if (i == 32) {       im = jLabel32;  } else if (i == 64) {       im = jLabel64;  } else if (i == 128) {       im = jLabel128;  } else if (i == 256) {       im = jLabel256;  } else if (i == 512) {       im = jLabel512;  } else if (i == 1024) {   im = jLabel1024;  } else if (i == 2048) {       im = jLabel2048;  } else if (i == -1) {       // System.out.println("出现数字1");       im = jLabel1;  } else if (i == 0) {       im = jLabel0;  }      return im; } public text(int[][] array) {  panel1.setLayout(new GridLayout(4, 4));  JLabel image = null;  for (int i = 0; i < 4; i++) {       for (int j = 0; j < 4; j++) {            image = Image(array[i][j]);            add(image);//此处应该是问题所在//panel1.add(new Label(String.valueOf(array[i][j])));                   }  }  setLayout(new GridBagLayout());  GridBagConstraints c = new GridBagConstraints();  c.gridx = c.gridy = 0;  add(panel1, c); }//在main中调用text(int[][] array);text(int[][] array)中调用 Image(int i);根据传入不同的数字,分别输出对应的图片。如果用panel1.add(new Label(String.valueOf(array[i][j])));该语句的话,可以在界面中输出数字,可是用image = Image(array[i][j]);    add(image);   。界面里什么都没有,求解答。。。。。谢谢
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 1082 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号