KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.prevayler.demos.demo2.gui;
2
3 import java.text.DateFormat JavaDoc;
4 import java.text.SimpleDateFormat JavaDoc;
5
6 import javax.swing.Box JavaDoc;
7 import javax.swing.JDesktopPane JavaDoc;
8 import javax.swing.JFrame JavaDoc;
9 import javax.swing.JInternalFrame JavaDoc;
10 import javax.swing.JLabel JavaDoc;
11
12 import org.prevayler.Prevayler;
13
14 public class BankFrame extends JFrame JavaDoc {
15
16     private final Prevayler _prevayler;
17
18     public BankFrame(Prevayler prevayler) {
19             super("Bank");
20             _prevayler = prevayler;
21             
22         setDefaultCloseOperation(EXIT_ON_CLOSE);
23
24         JDesktopPane JavaDoc desktop = new JDesktopPane JavaDoc();
25         setContentPane(desktop);
26         new AllAccountsFrame(prevayler, desktop);
27         desktop.add(new RobustnessFrame());
28         
29         setBounds(40,40,550,420);
30         setVisible(true);
31
32         refreshClock();
33     }
34
35
36     private void refreshClock() {
37         Thread JavaDoc clockRefresher = new Thread JavaDoc() {
38             public void run() {
39                 while (true) {
40                     DateFormat JavaDoc format = new SimpleDateFormat JavaDoc("hh:mm:ss");
41                     setTitle("Bank - " + format.format(_prevayler.clock().time()));
42                     try { Thread.sleep(500); } catch (InterruptedException JavaDoc e) {}
43                 }
44             }
45         };
46         clockRefresher.setDaemon(true);
47         clockRefresher.start();
48     }
49
50     
51     private static class RobustnessFrame extends JInternalFrame JavaDoc {
52         RobustnessFrame() {
53             super("Robustness Reminder", false, false, false, true);
54             setContentPane(Box.createVerticalBox());
55             
56             addLine(" You can kill this process at any time. ");
57             addLine(" When you run the application again, ");
58             addLine(" you will see that nothing was lost. ");
59             
60             setBackground(new java.awt.Color JavaDoc(204,204,204));
61             setBounds(300,300,235,90);
62             setVisible(true);
63         }
64         
65         private void addLine(String JavaDoc line) {
66             JLabel JavaDoc label = new JLabel JavaDoc(line);
67             label.setAlignmentX(0.5f);
68             getContentPane().add(label);
69         }
70     }
71
72 }
73
Popular Tags