KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > prevayler > demos > demo2 > gui > AccountFrame


1 package org.prevayler.demos.demo2.gui;
2
3 import java.awt.BorderLayout JavaDoc;
4 import java.awt.Color JavaDoc;
5 import java.awt.Component JavaDoc;
6 import java.awt.Container JavaDoc;
7 import java.text.DecimalFormat JavaDoc;
8 import java.text.ParseException JavaDoc;
9
10 import javax.swing.Box JavaDoc;
11 import javax.swing.JInternalFrame JavaDoc;
12 import javax.swing.JLabel JavaDoc;
13 import javax.swing.JPanel JavaDoc;
14 import javax.swing.JTextField JavaDoc;
15
16 import org.prevayler.Prevayler;
17
18
19 abstract class AccountFrame extends JInternalFrame JavaDoc {
20
21     protected final Prevayler _prevayler;
22     protected final JTextField JavaDoc holderField = new JTextField JavaDoc();
23
24     protected String JavaDoc holderText() {
25         return holderField.getText();
26     }
27         
28     AccountFrame(String JavaDoc title, Prevayler prevayler, Container JavaDoc container) {
29         super(title, false, true); //Not resizable. Closable.
30
_prevayler = prevayler;
31
32         container.add(this);
33         this.setBackground(new Color JavaDoc(204, 204, 204));
34
35         getContentPane().add(Box.createVerticalStrut(4), BorderLayout.NORTH);
36         getContentPane().add(Box.createHorizontalStrut(4), BorderLayout.EAST);
37         getContentPane().add(Box.createHorizontalStrut(4), BorderLayout.WEST);
38         getContentPane().add(fieldBox(), BorderLayout.CENTER);
39         getContentPane().add(buttonPanel(), BorderLayout.SOUTH);
40         
41         show();
42         holderField.requestFocus();
43     }
44     
45     private Box JavaDoc fieldBox() {
46         Box JavaDoc fieldBox = Box.createVerticalBox();
47         addFields(fieldBox);
48         return fieldBox;
49     }
50     
51     protected void addFields(Box JavaDoc fieldBox) {
52         fieldBox.add(labelContainer("Holder"));
53         fieldBox.add(holderField);
54     };
55         
56     private JPanel JavaDoc buttonPanel() {
57         JPanel JavaDoc buttonPanel = new JPanel JavaDoc();
58         addButtons(buttonPanel);
59         return buttonPanel;
60     }
61     
62     abstract protected void addButtons(JPanel JavaDoc buttonPanel);
63
64     protected Container JavaDoc labelContainer(String JavaDoc text) {
65         Box JavaDoc box = Box.createHorizontalBox();
66         JLabel JavaDoc label = new JLabel JavaDoc(text);
67         box.add(label);
68         box.add(Box.createHorizontalGlue());
69         return box;
70     }
71
72     protected Component JavaDoc gap() {
73         return Box.createVerticalStrut(3);
74     }
75
76     protected long parse(String JavaDoc numericString) throws ParseException JavaDoc {
77         return new DecimalFormat JavaDoc("#").parse(numericString).longValue(); //The exception thrown has a better message than Long.parseLong(String).
78
}
79
80 }
81
Popular Tags