/Users/lyon/j4p/src/gui/run/RunPasswordField.java

1    package gui.run; 
2     
3    import javax.swing.*; 
4    import java.awt.event.ActionListener; 
5    import java.awt.event.KeyEvent; 
6    import java.awt.event.KeyListener; 
7     
8     
9    public abstract class RunPasswordField 
10           extends JPasswordField 
11           implements ActionListener, 
12                      KeyListener, Runnable { 
13       String sTxt; 
14    
15       public RunPasswordField(String text) { 
16           super(text); 
17           addActionListener(this); 
18           addKeyListener(this); 
19       } 
20    
21       public void keyTyped(KeyEvent e) { 
22       }; 
23    
24       public void keyPressed(KeyEvent e) { 
25       }; 
26    
27       public void keyReleased(KeyEvent e) { 
28           run(); 
29       }; 
30    
31       public RunPasswordField() { 
32           addActionListener(this); 
33           addKeyListener(this); 
34       } 
35    
36       public RunPasswordField(int columns) { 
37           super(columns); 
38           addActionListener(this); 
39           addKeyListener(this); 
40       } 
41    
42       public RunPasswordField(String text, 
43                               int columns) { 
44           super(text, columns); 
45           addActionListener(this); 
46           addKeyListener(this); 
47       } 
48    
49       public RunPasswordField( 
50               javax.swing.text.Document doc, 
51               String text, 
52               int columns) { 
53           super(doc, text, columns); 
54           addActionListener(this); 
55           addKeyListener(this); 
56       } 
57    
58       public String getPasswordString() { 
59           return new String(super.getPassword()); 
60       } 
61    
62       public void actionPerformed( 
63               java.awt.event.ActionEvent e) { 
64           run(); 
65       } 
66    
67       public static void main(String args[]) { 
68           gui.ClosableJFrame cf = new gui.ClosableJFrame( 
69                   "RunPasswordField"); 
70           java.awt.Container c = cf.getContentPane(); 
71           c.add(new RunPasswordField( 
72                   "What is your password?") { 
73               public void run() { 
74                   System.out.println(getPassword()); 
75    
76               } 
77           }); 
78           c.setLayout( 
79                   new java.awt.GridLayout(4, 0)); 
80           cf.setSize(200, 200); 
81           cf.setVisible(true); 
82       } 
83    
84   }