// This method is an event handler called whenever an actionEvent is received (assuming an event
 // listener has been
 // added, which is done a TealAction is created).  This method should contain the code you want to
 // run when each
 // ActionEvent is received.
 public void actionPerformed(ActionEvent e) {
   // If the ActionEvent received is the one corresponding to our Help menu item added above,
   // launch the help file.
   if (e.getActionCommand().compareToIgnoreCase("Gauss's Law for a Dipole and Disk") == 0) {
     if (mFramework instanceof TFramework) {
       ((TFramework) mFramework).openBrowser("help/gausslawmagdipoledisk.html");
     }
   } else if (e.getActionCommand().compareToIgnoreCase("Execution & View") == 0) {
     if (mFramework instanceof TFramework) {
       ((TFramework) mFramework).openBrowser("help/executionView.html");
     }
   } else {
     super.actionPerformed(e);
   }
 }
Exemple #2
0
 public void actionPerformed(ActionEvent e) {
   String command = e.getActionCommand();
   System.out.println("Action: " + command);
   if (e.getActionCommand().compareToIgnoreCase("Capacitor2") == 0) {
     if ((mFramework != null) && (mFramework instanceof TFramework)) {
       ((TFramework) mFramework).openBrowser("help/capacitor.html");
     } else {
       TDebug.println("mFramework is null!");
     }
   } else if (e.getSource() == plate1Number) {
     int value = 0;
     try {
       value = Integer.parseInt(plate1Number.getText());
     } catch (NumberFormatException exception) {
       return;
     }
     if (value < 0) {
       value = 0;
       plate1Number.setText("0");
     }
     int change = value - pcList1.size();
     if (change > 0) {
       addChargesToList1(change);
     } else {
       removeChargesFromList1(-change);
     }
   } else if (e.getSource() == plate2Number) {
     int value = 0;
     try {
       value = Integer.parseInt(plate2Number.getText());
     } catch (NumberFormatException exception) {
       return;
     }
     if (value < 0) {
       value = 0;
       plate2Number.setText("0");
     }
     int change = value - pcList2.size();
     if (change > 0) {
       addChargesToList2(change);
     } else {
       removeChargesFromList2(-change);
     }
   } else if (e.getSource() == plate1Charge) {
     double value = 0.;
     try {
       value = Double.parseDouble(plate1Charge.getText());
     } catch (NumberFormatException exception) {
       return;
     }
     for (int i = 0; i < pcList1.size(); i++) {
       PointCharge pc = (PointCharge) pcList1.get(i);
       pc.setCharge(value);
     }
   } else if (e.getSource() == plate2Charge) {
     double value = 0.;
     try {
       value = Double.parseDouble(plate2Charge.getText());
     } catch (NumberFormatException exception) {
       return;
     }
     for (int i = 0; i < pcList2.size(); i++) {
       PointCharge pc = (PointCharge) pcList2.get(i);
       pc.setCharge(value);
     }
   } else {
     super.actionPerformed(e);
   }
 }