/Users/lyon/j4p/src/addBk/address/AddressPanel.java

1    package addBk.address; 
2     
3    import javax.swing.*; 
4    import javax.swing.border.TitledBorder; 
5    import java.awt.*; 
6    import java.awt.event.TextEvent; 
7     
8    public class AddressPanel extends JPanel 
9            implements AddressSettable { 
10    
11       public void textValueChanged(TextEvent e) { 
12           System.out.println(e); 
13       } 
14    
15       public void setAddress(AddressRecord a) { 
16           ta1.setText(a.getAddress1()); 
17           ta2.setText(a.getAddress2()); 
18       } 
19    
20       JTextArea ta2 = getTextArea("address2",'b'); 
21       JTextArea ta1 = getTextArea("address1",'a'); 
22    
23       AddressPanel() { 
24           setLayout(new GridLayout(0,1)); 
25           add(ta1,BorderLayout.NORTH); 
26           add(ta2,BorderLayout.SOUTH); 
27    
28       } 
29    
30       private JTextArea getTextArea(String label,char accelerator) { 
31           JTextArea ta1 = new JTextArea(5,30); 
32           TitledBorder titledBorder = BorderFactory.createTitledBorder(label); 
33           ta1.setBorder(titledBorder); 
34           ta1.setToolTipText(label); 
35           ta1.setFocusAccelerator(accelerator); 
36           ta1.setLineWrap(true); 
37           ta1.setEditable(true); 
38           return ta1; 
39       } 
40   }