public TextFields() {
   t1.setDocument(ucd);
   ucd.addDocumentListener(new T1());
   b1.addActionListener(new B1());
   b2.addActionListener(new B2());
   t1.addActionListener(new T1A());
   setLayout(new FlowLayout());
   add(b1);
   add(b2);
   add(t1);
   add(t2);
   add(t3);
 }
示例#2
0
 public RadioButtons() {
   rb1.addActionListener(al);
   rb2.addActionListener(al);
   rb3.addActionListener(al);
   g.add(rb1);
   g.add(rb2);
   g.add(rb3);
   t.setEditable(false);
   setLayout(new FlowLayout());
   add(t);
   add(rb1);
   add(rb2);
   add(rb3);
 }
示例#3
0
 public void actionPerformed(ActionEvent e) {
   String id = ((JButton) e.getSource()).getText();
   if (id.equals("Alert"))
     JOptionPane.showMessageDialog(
         null, "There's a bug on you!", "Hey!", JOptionPane.ERROR_MESSAGE);
   else if (id.equals("Yes/No"))
     JOptionPane.showConfirmDialog(null, "or no", "choose yes", JOptionPane.YES_NO_OPTION);
   else if (id.equals("Color")) {
     Object[] options = {"Red", "Green"};
     int sel =
         JOptionPane.showOptionDialog(
             null,
             "Choose a Color!",
             "Warning",
             JOptionPane.DEFAULT_OPTION,
             JOptionPane.WARNING_MESSAGE,
             null,
             options,
             options[0]);
     if (sel != JOptionPane.CLOSED_OPTION) txt.setText("Color Selected: " + options[sel]);
   } else if (id.equals("Input")) {
     String val = JOptionPane.showInputDialog("How many fingers do you see?");
     txt.setText(val);
   } else if (id.equals("3 Vals")) {
     Object[] selections = {"First", "Second", "Third"};
     Object val =
         JOptionPane.showInputDialog(
             null,
             "Choose one",
             "Input",
             JOptionPane.INFORMATION_MESSAGE,
             null,
             selections,
             selections[0]);
     if (val != null) txt.setText(val.toString());
   }
 }
示例#4
0
 public ComboBoxes() {
   for (int i = 0; i < 4; i++) c.addItem(description[count++]);
   t.setEditable(false);
   b.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           if (count < description.length) c.addItem(description[count++]);
         }
       });
   c.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           t.setText(
               "index: "
                   + c.getSelectedIndex()
                   + "   "
                   + ((JComboBox) e.getSource()).getSelectedItem());
         }
       });
   setLayout(new FlowLayout());
   add(t);
   add(c);
   add(b);
 }
示例#5
0
 public void actionPerformed(ActionEvent e) {
   t.setText("Radio button " + ((JRadioButton) e.getSource()).getText());
 }