• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

2048的一段代码,求解答?

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[j]);
            add(image);//此处应该是问题所在
//panel1.add(new Label(String.valueOf(array[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[j])));该语句的话,可以在界面中输出数字,可是用image = Image(array[j]);    add(image);   。界面里什么都没有,求解答。。。。。谢谢

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!