Advertisement
guitarman0831

Untitled

Jun 12th, 2011
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. import java.awt.FlowLayout;
  2. import java.awt.event.ActionListener;
  3. import java.awt.event.ActionEvent;
  4. import javax.swing.JFrame;
  5. import javax.swing.JTextField;
  6. import javax.swing.JPasswordField;
  7. import javax.swing.JOptionPane;
  8.  
  9. public class tuna extends JFrame {
  10.     private JTextField item1;
  11.     private JTextField item2;
  12.     private JTextField item3;
  13.     private JPasswordField passwordfield;
  14.    
  15.     public tuna() {
  16.         super("The Title");
  17.         setLayout(new FlowLayout());
  18.        
  19.         item1 = new JTextField(10);
  20.         add(item1);
  21.        
  22.         item2 = new JTextField("Enter Text Here");
  23.         add(item2);
  24.        
  25.         item3 = new JTextField("Uneditable, 20");
  26.         item3.setEditable(false);
  27.         add(item3);
  28.        
  29.         passwordfield = new JPasswordField("mypass");
  30.         add(passwordfield);
  31.        
  32.         thehandler handler = new thehandler();
  33.         item1.addActionListener(handler);
  34.         item2.addActionListener(handler);
  35.         item3.addActionListener(handler);
  36.         passwordfield.addActionListener(handler);
  37.     }
  38.    
  39.     private class thehandler implements ActionListener {
  40.         public void actionPerformed(ActionEvent event){
  41.             String string = "";
  42.             if(event.getSource() == item1){
  43.                 string = String.format("field 1: %s",event.getActionCommand());
  44.             } else if(event.getSource() == item2){
  45.                 string = String.format("field 2: %s",event.getActionCommand());
  46.             } else if(event.getSource() == item3){
  47.                 string = String.format("field 3: %s",event.getActionCommand());
  48.             } else if(event.getSource() == passwordfield){
  49.                 string = String.format("Password: %s",event.getActionCommand());
  50.             }
  51.             JOptionPane.showMessageDialog(null, string);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement