Pārlūkot izejas kodu

CubeWorker will now be informed about selection change in animations

unknown 12 gadus atpakaļ
vecāks
revīzija
d8e4a33d2b
2 mainītis faili ar 21 papildinājumiem un 5 dzēšanām
  1. 1
    1
      Cube Control/cubeWorker.java
  2. 20
    4
      Cube Control/frame.java

+ 1
- 1
Cube Control/cubeWorker.java Parādīt failu

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

+ 20
- 4
Cube Control/frame.java Parādīt failu

1
 import java.awt.*;
1
 import java.awt.*;
2
 import java.awt.event.*;
2
 import java.awt.event.*;
3
 import javax.swing.*;
3
 import javax.swing.*;
4
+import javax.swing.event.*;
4
 
5
 
5
 /*
6
 /*
6
  * frame.java
7
  * frame.java
77
   }
78
   }
78
 
79
 
79
   private void errorMessage(String s) {
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
   public frame(String title) {
85
   public frame(String title) {
347
     jList2.setFont(new Font("Dialog", Font.PLAIN, 13));
348
     jList2.setFont(new Font("Dialog", Font.PLAIN, 13));
348
     frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
349
     frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
349
     // Ende Komponenten
350
     // Ende Komponenten
350
-
351
+    jList2.addListSelectionListener(new MyListSelectionListener(jList2, worker));
351
     setResizable(false);
352
     setResizable(false);
352
     setVisible(true);
353
     setVisible(true);
353
   }
354
   }
467
 
468
 
468
   public void download_ActionPerformed(ActionEvent evt) {
469
   public void download_ActionPerformed(ActionEvent evt) {
469
          if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
470
          if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
470
-			errorMessage("No serial port selected...");
471
+      errorMessage("No serial port selected...");
471
          } else {
472
          } else {
472
            worker.downloadState((String)jComboBox1.getSelectedItem());
473
            worker.downloadState((String)jComboBox1.getSelectedItem());
473
          }
474
          }
481
   // Ende Methoden
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
+

Notiek ielāde…
Atcelt
Saglabāt