Exemple #1
0
    public void actionPerformed(ActionEvent e) {
      JButton source = (JButton) e.getSource();
      _usrVotes[_index] = source.getText();

      for (JButton b : _candidateButtons) {
        b.setForeground(Color.BLACK);
      }
      source.setForeground(Color.RED);

      System.out.println("Vote for " + _title + " is " + _usrVotes[_index]);
    }
 public void actionPerformed(ActionEvent e) {
   if (e.getSource().equals(pausePlay)) {
     if (pausePlay.getText().equals("Play")) {
       pausePlay.setText("Pause");
       LifeSimulation.timer().start();
     } else {
       pausePlay.setText("Play");
       LifeSimulation.timer().stop();
     }
   }
 }
 public void testStringProperty() throws Exception {
   JComponent rootComponent =
       getInstrumentedRootComponent("TestGridConstraints.form", "BindingTest");
   JButton btn = (JButton) rootComponent.getComponent(0);
   assertEquals("MyTestButton", btn.getText());
 }
Exemple #4
0
  public void actionPerformed(ActionEvent ae) {
    // clear display if new number is to be entered
    if (doClear) display.setText(null);

    // if decimal point is entered for the first time in number
    if ((ae.getSource() == point) && decPoint == false) {
      display.append(".");
      // disallow more decimal points
      decPoint = true;
    }

    // if decimal point is the first in a number, display "0."
    if (display.getText().equals(".")) display.setText("0.");

    // check if a digit was clicked
    for (int i = 0; i < 10; i++) {

      // append digits to number while number is less than 15 digits long
      if ((ae.getSource() == jb[i]) && (display.getText().length() < 15)) {

        display.append(((JButton) ae.getSource()).getText());

        // disallow leading zeros
        if (display.getText().equals("0")) display.setText("0.");

        // store as a Double
        secondNum = Double.parseDouble(display.getText());
        System.out.println("SecondNum is: " + secondNum);

        doClear = false;
        // only if you click another digit
        oldOp = false;
      }
    }

    // check if an operator was clicked
    if ((ae.getSource() == plus)
        || (ae.getSource() == minus)
        || (ae.getSource() == div)
        || (ae.getSource() == mult)) {
      decPoint = false;
      if (oldOp == false) {
        // if this is the first time an operator was clicked
        if (operators) {
          // the number last entered becomes the first number
          firstNum = secondNum;
          System.out.println("firstNum is: " + secondNum);
        } else {

          calc();
        }

        // store the operator that was clicked
        JButton temp = (JButton) ae.getSource();
        operator = temp.getText();
        System.out.println("Operator is: " + operator);
        operators = false;
        doClear = true;
        oldOp = true;
      }
      // if an operator was clicked without a digit having been entered between
      else {
        // store the operator that was clicked
        JButton temp = (JButton) ae.getSource();
        operator = temp.getText();
        System.out.println("Operator is: " + operator);
        display.setText(String.valueOf(firstNum));
      }
    }

    if (ae.getSource() == root) {
      squareRoot();
      decPoint = false;
    }

    if (ae.getSource() == clear) {
      clear();
    }

    if (ae.getSource() == equals) {
      calc();
    }
  }
Exemple #5
0
 public void mouseClicked(MouseEvent e) {
   if (e.getSource() == userList && e.getClickCount() == 2) {
     int index = userList.locationToIndex(e.getPoint());
     if (index > -1) {
       String userInfo = (String) ((DefaultListModel) userList.getModel()).get(index);
       link.running = false;
       userInfo = userInfo.substring(userInfo.indexOf("@") - 1);
       link =
           new LeetClient(
               userInfo.substring(userInfo.indexOf("@") + 1, userInfo.indexOf(":")),
               Integer.parseInt(userInfo.substring(userInfo.indexOf(":") + 1)),
               address,
               directory);
       link.setPasv(portItem.getState());
       link.command = "LIST";
       link.start();
     }
   }
   if (e.getSource() == fileList && e.getClickCount() == 2) {
     int index = fileList.locationToIndex(e.getPoint());
     if (index > -1) {
       String fileName = (String) ((DefaultListModel) fileList.getModel()).get(index);
       if (fileName.indexOf(" ") > -1) {
         fileName = fileName.substring(0, fileName.indexOf(" "));
       }
       link.command = "RETR " + fileName;
       System.out.println(link.command);
     }
   }
   if (e.getSource() == connectButton) {
     if (connectButton.getText().equals("Disconnect")) {
       active.running = false;
       connectButton.setText("Connect");
     } else {
       active =
           new LeetActive(
               serverTextField.getText(),
               Integer.parseInt(portTextField.getText()),
               SERVER_PORT);
       active.setUserName(nameTextField.getText());
       active.start();
       connectButton.setText("Disconnect");
     }
   }
   if (e.getSource() == searchInit) {
     search = new SearchUsers();
     search.start();
   }
   if (e.getSource() == searchList && e.getClickCount() == 2) {
     int index = searchList.locationToIndex(e.getPoint());
     if (index > -1) {
       String fileInfo = (String) ((DefaultListModel) searchList.getModel()).get(index);
       link.running = false;
       String userInfo = fileInfo.substring(fileInfo.indexOf("@") + 1);
       userInfo = userInfo.substring(userInfo.indexOf("@") - 1);
       fileInfo = fileInfo.substring(0, fileInfo.indexOf("@"));
       link =
           new LeetClient(
               userInfo.substring(userInfo.indexOf("@") + 1, userInfo.indexOf(":")),
               Integer.parseInt(userInfo.substring(userInfo.indexOf(":") + 1)),
               address,
               directory);
       link.setPasv(portItem.getState());
       link.command = "RETR " + fileInfo;
       link.start();
     }
   }
 }
  public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource();
    if (b.getText() == "PLAY") {
      if (scoreP != null) scoreP.playScale(sp.getScale(), tempoP.getValue());
    } else if (b.getText() == "New") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      sp.notes.removeAllElements();
      sp.repaint();
      nameTF.setText("");
      loadedFile = null;
    } else if (b.getText() == "Save") {
      if (nameTF.getText().equals("")) {
        JOptionPane.showMessageDialog(
            this,
            new JLabel("Please type in the Scale Name"),
            "Warning",
            JOptionPane.WARNING_MESSAGE);
        return;
      }
      fileChooser.setFileFilter(filter);
      int option = fileChooser.showSaveDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        File target = fileChooser.getSelectedFile();
        if (target.getName().indexOf(".scl") == -1) target = new File(target.getPath() + ".scl");
        try {
          PrintStream stream = new PrintStream(new FileOutputStream(target), true);
          save(stream);
          stream.close();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
        }
      }
    } else if (b.getText() == "Load") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      fileChooser.setFileFilter(filter);
      int option = fileChooser.showOpenDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        loadedFile = fileChooser.getSelectedFile();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        ScaleParser handler = new ScaleParser(false);
        try {
          SAXParser parser = factory.newSAXParser();
          parser.parse(loadedFile, handler);
          // System.out.println("success");
        } catch (Exception ex) {
          // System.out.println("no!!!!!! exception: "+e);
          // System.out.println(ex.getMessage());
          ex.printStackTrace();
        }
        // -----now :P:P---------------
        System.out.println("name: " + handler.getName());
        nameTF.setText(handler.getName());
        sp.notes.removeAllElements();
        int[] scale = handler.getScale();
        for (int i = 0; i < scale.length; i++) {
          sp.addNote(scale[i]);
        }
        sp.repaint();
      } else loadedFile = null;
    }
  }