KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xenon > free > swing > DigitalClockDemo


1 /* $Id$
2  *
3  * Copyright (c) 1998 Xenonsoft Limited. All Rights Reserved.
4  *
5  * This software is protected by copyright. You are hereby notified from
6  * now by reading this message. This software is also the confidential
7  * and proprietary information of Xenonsoft Limited. ("Confidential
8  * Information").
9  *
10  * This software is distributed under the Xenonsoft Public end user
11  * License ("XPeL"), where the machine-readable source code is provided
12  * under the "Open Source" model.
13  * For more information, please read the file "LICENSE-XPL.txt"
14  */

15
16 //
17
// DESCRIPTION
18
//
19
// The Digital Clock Demo
20
// Peter Pilgrim Sun Mar 07 22:50:08 GMT 1999
21
//
22
// RCS HEADER
23
//
24
// $Author$
25
// $Date$
26
// $Source$
27
// $Revision$ $State$ $Locker$
28
//
29
package xenon.free.swing;
30
31 import java.awt.*;
32 import java.awt.event.*;
33 import javax.swing.*; // for JFrame, JOptionPane
34
import javax.swing.event.*;
35
36 public class DigitalClockDemo extends JFrame
37 implements ActionListener
38 {
39     private DigitalClock clock;
40     private JButton bt_start, bt_stop;
41     
42     public DigitalClockDemo( String JavaDoc title)
43     {
44     super(title);
45     
46     getContentPane().setLayout( new BorderLayout(5,5) );
47     
48     Font buttonFont = new Font("Dialog", Font.BOLD, 12 );
49     Font clockFont = new Font("Dialog", Font.BOLD, 18 );
50     
51     
52     bt_start = new JButton("Start");
53     bt_start.addActionListener(this);
54     getContentPane().add( bt_start, BorderLayout.WEST );
55     
56     bt_stop = new JButton("Stop");
57     bt_stop.setEnabled(false);
58     bt_stop.addActionListener(this);
59     getContentPane().add( bt_stop, BorderLayout.EAST );
60     
61     clock = new DigitalClock();
62     clock.setMode24Hours(false);
63     clock.setFont( clockFont );
64     getContentPane().add( clock, BorderLayout.CENTER );
65     }
66     
67     public void actionPerformed( ActionEvent e )
68     {
69     Object JavaDoc src = e.getSource();
70     if ( bt_start == src ) {
71         bt_start.setEnabled(false);
72         bt_stop.setEnabled(true);
73         clock.start();
74     }
75     else if ( bt_stop == src ) {
76         bt_start.setEnabled(true);
77         bt_stop.setEnabled(false);
78         clock.stop();
79     }
80     }
81     
82     public static void main( String JavaDoc [] args )
83     {
84     DigitalClockDemo dc = new DigitalClockDemo("Digital Clock Demo!");
85     dc.pack();
86     dc.setVisible(true);
87     dc.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
88     }
89
90 }
91 // fini
92
Popular Tags