1 package org.prevayler.demos.demo2.gui; 2 3 import java.text.DateFormat ; 4 import java.text.SimpleDateFormat ; 5 6 import javax.swing.Box ; 7 import javax.swing.JDesktopPane ; 8 import javax.swing.JFrame ; 9 import javax.swing.JInternalFrame ; 10 import javax.swing.JLabel ; 11 12 import org.prevayler.Prevayler; 13 14 public class BankFrame extends JFrame { 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 desktop = new JDesktopPane (); 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 clockRefresher = new Thread () { 38 public void run() { 39 while (true) { 40 DateFormat format = new SimpleDateFormat ("hh:mm:ss"); 41 setTitle("Bank - " + format.format(_prevayler.clock().time())); 42 try { Thread.sleep(500); } catch (InterruptedException e) {} 43 } 44 } 45 }; 46 clockRefresher.setDaemon(true); 47 clockRefresher.start(); 48 } 49 50 51 private static class RobustnessFrame extends JInternalFrame { 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 (204,204,204)); 61 setBounds(300,300,235,90); 62 setVisible(true); 63 } 64 65 private void addLine(String line) { 66 JLabel label = new JLabel (line); 67 label.setAlignmentX(0.5f); 68 getContentPane().add(label); 69 } 70 } 71 72 } 73 | Popular Tags |