浏览代码

Clicking the LED-Buttons now actually changes the xolor of the button.

Max Nuding 12 年前
父节点
当前提交
e9465e7579
共有 1 个文件被更改,包括 13 次插入6 次删除
  1. 13
    6
      Cube Control/layerEditFrame.java

+ 13
- 6
Cube Control/layerEditFrame.java 查看文件

16
   private JPanel panelLED1 = new JPanel(null, true);
16
   private JPanel panelLED1 = new JPanel(null, true);
17
   JButton[][] ledPanels = new JButton[8][8];
17
   JButton[][] ledPanels = new JButton[8][8];
18
   static ImageIcon on = new ImageIcon("LEDon.png");
18
   static ImageIcon on = new ImageIcon("LEDon.png");
19
-  static ImageIcon off = new ImageIcon("LEDff.png");
19
+  static ImageIcon off = new ImageIcon("LEDoff.png");
20
 
20
 
21
   // Ende Attribute
21
   // Ende Attribute
22
 
22
 
37
 
37
 
38
     for(int i = 0; i < 8; i++){
38
     for(int i = 0; i < 8; i++){
39
       for(int j = 0; j < 8; j++){
39
       for(int j = 0; j < 8; j++){
40
+         final int finalI = i;
41
+         final int finalJ = j;
40
          ledPanels[i][j] = new JButton(on);
42
          ledPanels[i][j] = new JButton(on);
41
          ledPanels[i][j].setBounds((i*20)+5, (j*20)+5, 15, 15);
43
          ledPanels[i][j].setBounds((i*20)+5, (j*20)+5, 15, 15);
44
+         ledPanels[i][j].addActionListener(new ActionListener() {
45
+           public void actionPerformed(ActionEvent evt) {
46
+             btnClicked(finalI, finalJ);
47
+           }
48
+         });
42
          ledPanels[i][j].setVisible(true);
49
          ledPanels[i][j].setVisible(true);
43
          cp.add(ledPanels[i][j]);
50
          cp.add(ledPanels[i][j]);
44
       }
51
       }
80
     // Anfang Komponenten
87
     // Anfang Komponenten
81
 
88
 
82
     // Ende Komponenten
89
     // Ende Komponenten
83
-  /*public void btnClicked(){
84
-    if (getIcon() == on){
85
-      setIcon(off);
90
+  public void btnClicked(int i, int j){
91
+    if (ledPanels[i][j].getIcon() == on){
92
+      ledPanels[i][j].setIcon(off);
86
     } else {
93
     } else {
87
-      setIcon(on);
94
+      ledPanels[i][j].setIcon(on);
88
     }
95
     }
89
-  } */
96
+  }
90
 
97
 
91
   public void cancel(){
98
   public void cancel(){
92
     dispose();
99
     dispose();

正在加载...
取消
保存