public void actionPerformed(ActionEvent event) {
    Object source = event.getSource();
    if (boundedRangeModel != null) {
      int value = boundedRangeModel.getValue();
      if (source == forwardButton) {
        boundedRangeModel.setValue(
            value == boundedRangeModel.getMaximum() ? boundedRangeModel.getMinimum() : value + 1);
      } else if (source == rewindButton) {
        boundedRangeModel.setValue(
            value == boundedRangeModel.getMinimum() ? boundedRangeModel.getMaximum() : value - 1);
      } else if (source == startButton) {
        if (startButton.isSelected() != player.isActive()) {
          if (startButton.isSelected()) {
            player.start();
          } else {
            player.stop();
          }
        }
      } else if (source == audioButton) {

        player.setAudioEnabled(audioButton.isSelected());
      } else if (source == colorCyclingButton) {
        if (player instanceof ColorCyclePlayer) {
          ((ColorCyclePlayer) player).setColorCyclingStarted(colorCyclingButton.isSelected());
        }
      }
    }
  }
示例#2
0
 public void actionPerformed(ActionEvent event) {
   if (event.getSource() == joinButton) {
     if (joinButton.isSelected()) {
       mThread =
           new MulticastThread(
               Integer.valueOf(portField.getText()), chatIPField.getText(), chatroomArea, true);
       (new Thread(mThread)).start();
     }
   }
   if (event.getSource() == sendButton) {
     mThread.send(usernameField.getText(), chatMsgField.getText());
     chatMsgField.setText("");
   }
   if (event.getSource() == leaveButton) {
     try {
       joinButton.setSelected(false);
       mThread.leave();
       System.out.println("Disconnected from chat ");
     } catch (Exception e) {
     }
   }
   if (event.getSource() == exitButton) {
     System.exit(0);
   }
 }
示例#3
0
 public void actionPerformed(java.awt.event.ActionEvent e) {
   dlg.panelMain.mark.setObject(Obj.UNKOBJ);
   dlg.panelMain.mark.setCategory(Cat.NOCAT);
   dlg.panelMain.mark.setTopmark(Top.NOTOP);
   if (mooringButton.isSelected()) {
     dlg.panelMain.mark.setObject(Obj.MORFAC);
     categoryBox.setVisible(false);
     mooringBox.setVisible(true);
     pillarButton.setEnabled(false);
     sparButton.setEnabled(false);
     beaconButton.setEnabled(false);
     towerButton.setEnabled(false);
     stakeButton.setEnabled(false);
     cairnButton.setEnabled(false);
     mooringButton.setBorderPainted(true);
   } else {
     mooringBox.setVisible(false);
     categoryBox.setVisible(true);
     pillarButton.setEnabled(true);
     sparButton.setEnabled(true);
     beaconButton.setEnabled(true);
     towerButton.setEnabled(true);
     stakeButton.setEnabled(true);
     cairnButton.setEnabled(true);
     mooringButton.setBorderPainted(false);
   }
   syncPanel();
 }
示例#4
0
 public void actionPerformed(java.awt.event.ActionEvent e) {
   dlg.panelMain.mark.clrMark();
   if (noticeButton.isSelected()) {
     dlg.panelMain.mark.setObject(Obj.NOTMRK);
     noticeButton.setBorderPainted(true);
   } else {
     dlg.panelMain.mark.setObject(Obj.UNKOBJ);
     noticeButton.setBorderPainted(false);
   }
   dlg.panelMain.syncPanel();
 }
示例#5
0
  public void actionPerformed(java.awt.event.ActionEvent event) {
    if (TRACE) System.out.println("CutPanelView actionPerformed: view: " + viewName);

    if (event.getSource() == closeButn) {
      JToggleButton jtb = (JToggleButton) event.getSource();
      jtb.setSelected(false);
      // System.out.println("Close!");
      vm.hideView(this);
      toolbarButton.setSelected(false);
    } else if (toolbarButton.isSelected()) {
      vm.showView(this);
    } else vm.hideView(this);
  }
示例#6
0
 public void actionPerformed(java.awt.event.ActionEvent e) {
   if (topmarkButton.isSelected()) {
     dlg.panelMain.mark.setTopmark(Top.X_SHAPE);
     dlg.panelMain.mark.setTopPattern(Pat.NOPAT);
     dlg.panelMain.mark.setTopColour(Col.YELLOW);
     topmarkButton.setBorderPainted(true);
   } else {
     dlg.panelMain.mark.setTopmark(Top.NOTOP);
     dlg.panelMain.mark.setTopPattern(Pat.NOPAT);
     dlg.panelMain.mark.setTopColour(Col.UNKCOL);
     topmarkButton.setBorderPainted(false);
   }
   dlg.panelMain.panelTop.syncPanel();
 }
 private void handleRegister() {
   if (session == null || !session.isConnected()) {
     jToggleButtonRegister.setSelected(false);
     jMenuItemOptionsDeregister.setEnabled(false);
     jMenuItemOptionsRegister.setEnabled(true);
     return;
   }
   if (jToggleButtonRegister.isSelected() || jMenuItemOptionsRegister.isEnabled()) {
     register();
     jToggleButtonRegister.setText("Deregister");
     jMenuItemOptionsDeregister.setEnabled(true);
     jMenuItemOptionsRegister.setEnabled(false);
   } else {
     deregister();
     jToggleButtonRegister.setText("Register");
     jMenuItemOptionsDeregister.setEnabled(false);
     jMenuItemOptionsRegister.setEnabled(true);
   }
 }
 private void handleConnect() {
   if (jToggleButtonConnect.isSelected() || jMenuItemServerConnect.isEnabled())
     try {
       jTextPaneDisplayMessages.setText("");
       session = new Session();
       try {
         String userid = jTextFieldUser.getText();
         if (jPasswordFieldPwd.getPassword() != null) {
           String pwd = String.valueOf(jPasswordFieldPwd.getPassword()).trim();
           if (!pwd.equals("")) {
             userid += ":" + pwd;
           }
         }
         if (session.connect(jTextFieldServer.getText(), userid)) {
           displayMessage("Connected\n", incomingMsgAttrSet);
           session.addListener(this);
           jToggleButtonConnect.setText("Disconnect");
           jMenuItemServerConnect.setEnabled(false);
           jMenuItemServerDisconnect.setEnabled(true);
         } else {
           jToggleButtonConnect.setSelected(false);
           jMenuItemServerConnect.setEnabled(true);
           jMenuItemServerDisconnect.setEnabled(false);
           displayMessage("Connection attempt failed\n", offlineClientAttrSet);
         }
       } catch (ConnectionException ex1) {
         jToggleButtonConnect.setSelected(false);
         jMenuItemServerConnect.setEnabled(true);
         jMenuItemServerDisconnect.setEnabled(false);
         displayMessage(
             "Connection attempt failed: " + ex1.getMessage() + "\n", offlineClientAttrSet);
       }
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   else {
     disconnect();
     jMenuItemServerConnect.setEnabled(true);
     jMenuItemServerDisconnect.setEnabled(false);
     displayMessage("Disconnected\n", offlineClientAttrSet);
   }
 }
示例#9
0
  // This is where all the action happens.  If an action is performed (button press for example), it
  // goes through this method
  // that takes an ActionEvent, which is created at the time of the action.
  public void actionPerformed(ActionEvent e) {
    // Try to cast the ActionEvent source as JToggleButton (if successful, the button is a ballot
    // choice)
    try {
      JToggleButton theButton = (JToggleButton) e.getSource();
      String buttonText = theButton.getText();

      if (theButton.isSelected()) {
        theButton.setForeground(Color.RED);
        switchButton = true;
        switchButtonText = buttonText;
        updateButtons(
            buttonText); // switches this button's respective vote position to 1 (true), meaning it
                         // is selected
      } else if (!theButton.isSelected()) {
        theButton.setForeground(Color.BLACK);
        unvoteButton = true;
        unvoteButtonText = buttonText;
      }
      // If the program can't cast the source to a JToggleButton, cast it as a JButton, which is
      // 100% what the source will be at this point.
      // This button will be one of two things: the login button or the cast vote button.
    } catch (Exception exception) {
      JButton theButton = (JButton) e.getSource();

      String buttonText = theButton.getText();

      // If the user hits the Login button, check if the ID is valid.
      // If the ID is not valid, don't let them vote.  However, if it is valid, disable login and
      // enable everything else.
      if (buttonText.equals("Login")) {
        String voterID =
            JOptionPane.showInputDialog(theButton, "Enter your voter ID: ", "Login", 3);
        FileIO votersFile = new FileIO("voters.txt");
        ArrayList<Voter> voters = votersFile.createVoters();

        if (votersFile.checkValidID(voterID)) {
          Voter theVoter = voters.get(votersFile.getVoterIndex(voterID));
          if (theVoter.getVotedStatus().equals("false")) {
            setVoterID(voterID);
          } else {
            JOptionPane.showMessageDialog(
                theButton, "You already voted " + theVoter.getVoterName() + "!");
          }
        } else {
          JOptionPane.showMessageDialog(theButton, "Invalid ID!", "Error", 0);
        }
        // If the user hits the cast vote button, update the respective ballot files and disable
        // every button except
        // for the login button.
      } else if (buttonText.equals("Cast vote")) {
        int confirm = JOptionPane.showConfirmDialog(theButton, "Are you sure?");
        FileIO votersFile = new FileIO("voters.txt");
        ArrayList<Voter> voters = votersFile.createVoters();
        Voter theVoter = voters.get(votersFile.getVoterIndex(voterID));

        if (confirm == 0) {
          JOptionPane.showMessageDialog(theButton, "Thanks for voting!");
          updateBallots();
          votersFile.updateVoterFile(theVoter.getVoterID());
          setVoterID("-1");
          votersFile.initializeVoters();
        }
      }
    }
  }
示例#10
0
文件: LJ3MDApp.java 项目: eskilj/mvp
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    if (src == timer) {
      for (int i = 0; i < speed; i++) // integrate a few steps
      md.vv();
      repaint();
      return;
    }

    boolean adjCanvasScale = false;

    if (src == bTstat) md.thermostat = !md.thermostat;

    if (src == bPot) {
      md.ljPotential = !md.ljPotential;
      md.clearData();

      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    if (src == tTemp || src == bReset) {
      double kT = Double.parseDouble(tTemp.getText().trim());
      if (kT < 1e-8) {
        kT = 1e-8;
        tTemp.setText("  " + kT);
      }
      md.kT = kT;
      md.clearData();
    }

    if (src == tRho || src == bReset) {
      double rho = Double.parseDouble(tRho.getText().trim());
      if (rho < 1e-3) {
        rho = 1e-3;
        tRho.setText("   " + rho);
      }
      if (rho > 1.2) {
        rho = 1.2;
        tRho.setText("   " + rho);
      }
      md.setDensity(rho);
      md.clearData();
      adjCanvasScale = true;
    }

    if (src == tSpeed || src == bReset) {
      speed = Integer.parseInt(tSpeed.getText().trim());
      if (speed < 1) {
        speed = 1;
        tSpeed.setText("   " + speed);
      }
    }

    if (src == bRetime) md.clearData();

    if (src == bStart) {
      boolean on = bStart.isSelected();
      if (on) {
        timer.restart();
        bStart.setText("Pause");
      } else {
        timer.stop();
        bStart.setText("Resume");
      }
    }

    if (src == tNum) {
      int n = Integer.parseInt(tNum.getText().trim());
      if (n < 2) {
        n = 2;
        tNum.setText(" " + n);
      }
      md.N = n;
      md.init(md.rho);
      adjCanvasScale = true;
    }

    if (src == bReset) {
      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    canvas.refresh(md.getXWrap(), md.N, true, adjCanvasScale);

    repaint();
  }