public void actionPerformed(ActionEvent e) {
   String name = null;
   name =
       JOptionPane.showInputDialog(
           objUpdate.this,
           "Enter a name (eg. John Russell)",
           "Input Person",
           JOptionPane.QUESTION_MESSAGE);
   if (!(name == null)) {
     // prompt the user for a date
     String date = null;
     date =
         JOptionPane.showInputDialog(
             objUpdate.this,
             "Enter Date (eg. 06/17/1946)",
             "Input Person",
             JOptionPane.QUESTION_MESSAGE);
     if (!(date == null)) {
       // convert String to Date
       try {
         Date d = f.parse(date);
         p = new Person(name, d);
         persons.add(p);
         index = persons.lastIndexOf(p);
         displayRecord();
       } catch (ParseException ex) {
         JOptionPane.showMessageDialog(
             objUpdate.this, "Invalid date format!", "Input Error", JOptionPane.ERROR_MESSAGE);
       }
     }
   }
 }
예제 #2
0
 public PowerSupply() {
   super();
   String str = JOptionPane.showInputDialog("Enter frequency");
   this.frequency = Double.parseDouble(str);
   this.impedance = new Complex(0.0, 0.0);
 }