private void multiConnect() {
   if (jButtonMultiConnect.getText().equals("Multi-Connect")) {
     String res =
         JOptionPane.showInputDialog(this, "Enter number of connections", "Multi-Connect");
     if (res != null) {
       jButtonMultiConnect.setText("Multi-Disconnect");
       jMenuItemTestMulticonnect.setEnabled(false);
       jMenuItemTestMultidisconnect.setEnabled(true);
       int count = Integer.parseInt(res);
       MultiSessions = new Session[count];
       for (int i = 0; i < count; i++) {
         MultiSessions[i] = new Session();
         try {
           MultiSessions[i].connect(
               this.jTextFieldServer.getText(), this.jTextFieldUser.getText() + String.valueOf(i));
         } catch (ConnectionException ex1) {
         }
       }
     }
   } else {
     for (int i = 0; i < MultiSessions.length; i++) {
       try {
         ((Session) MultiSessions[i]).disconnect();
       } catch (Exception ex) {
         System.out.println("Error disconnectiong from session");
       }
     }
     jButtonMultiConnect.setText("Multi-Connect");
     jMenuItemTestMulticonnect.setEnabled(true);
     jMenuItemTestMultidisconnect.setEnabled(false);
   }
 }
示例#2
0
 public void actionPerformed(ActionEvent ae) {
   JButton b = (JButton) ae.getSource();
   //      System.out.println("NumberEar: button="+b.getText());
   int i = new Integer(b.getText()).intValue() - 1;
   number[date].setForeground(Color.BLUE);
   date = i;
   number[i].setForeground(Color.CYAN);
 }
示例#3
0
    public void mouseClicked(MouseEvent e) {
      if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 1) {
        JButton source = (JButton) e.getSource();

        String value = source.getText();
        int day = Integer.parseInt(value);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        Date selectDate = this.getSelectDate();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        MyDateChooseBtn.this.setText(simpleDateFormat.format(selectDate));
        Jtext.setText(simpleDateFormat.format(selectDate));

        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        //        System.out.println(year + "骞�" + month + "鏈�" + day + "鏃�");
        f.dispose();
      }
    }
示例#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();
    }
  }
  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;
    }
  }