Browse Source

Merge pull request #1 from hutattedonmyarm/master

CubeWorker will now be informed about selection change in animations
Thomas B 12 years ago
parent
commit
ae67faf5a7
2 changed files with 21 additions and 5 deletions
  1. 1
    1
      Cube Control/cubeWorker.java
  2. 20
    4
      Cube Control/frame.java

+ 1
- 1
Cube Control/cubeWorker.java View File

@@ -49,7 +49,7 @@ public class cubeWorker {
49 49
     // Selects an animation, on which the frame specific functions operate
50 50
     // Returns -1 if it does not exist
51 51
     public int selectAnimation(int index) {
52
-
52
+           System.out.println("Animation " + index + " selected");
53 53
            return -1;
54 54
     }
55 55
     

+ 20
- 4
Cube Control/frame.java View File

@@ -1,6 +1,7 @@
1 1
 import java.awt.*;
2 2
 import java.awt.event.*;
3 3
 import javax.swing.*;
4
+import javax.swing.event.*;
4 5
 
5 6
 /*
6 7
  * frame.java
@@ -77,8 +78,8 @@ public class frame extends JFrame {
77 78
   }
78 79
 
79 80
   private void errorMessage(String s) {
80
-	String[] Optionen = {"OK"};
81
-	JOptionPane.showOptionDialog(this, s, "Error!", JOptionPane.YES_OPTION, JOptionPane.ERROR_MESSAGE, null, Optionen, Optionen[0]);
81
+  String[] Optionen = {"OK"};
82
+  JOptionPane.showOptionDialog(this, s, "Error!", JOptionPane.YES_OPTION, JOptionPane.ERROR_MESSAGE, null, Optionen, Optionen[0]);
82 83
   }
83 84
 
84 85
   public frame(String title) {
@@ -347,7 +348,7 @@ public class frame extends JFrame {
347 348
     jList2.setFont(new Font("Dialog", Font.PLAIN, 13));
348 349
     frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
349 350
     // Ende Komponenten
350
-
351
+    jList2.addListSelectionListener(new MyListSelectionListener(jList2, worker));
351 352
     setResizable(false);
352 353
     setVisible(true);
353 354
   }
@@ -467,7 +468,7 @@ public class frame extends JFrame {
467 468
 
468 469
   public void download_ActionPerformed(ActionEvent evt) {
469 470
          if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
470
-			errorMessage("No serial port selected...");
471
+      errorMessage("No serial port selected...");
471 472
          } else {
472 473
            worker.downloadState((String)jComboBox1.getSelectedItem());
473 474
          }
@@ -481,3 +482,18 @@ public class frame extends JFrame {
481 482
   // Ende Methoden
482 483
 }
483 484
 
485
+class MyListSelectionListener implements ListSelectionListener {
486
+
487
+  JList alist;
488
+  cubeWorker worker;
489
+  MyListSelectionListener(JList animList, cubeWorker w){
490
+    alist = animList;
491
+    worker = w;
492
+  }
493
+  public void valueChanged(ListSelectionEvent evt) {
494
+    if (!evt.getValueIsAdjusting()) {
495
+       worker.selectAnimation(alist.getSelectedIndex());
496
+    }
497
+  }
498
+}
499
+

Loading…
Cancel
Save