3.13 The DatePanelDemonstration class

The DatePanelDemonstration client is presented below. Briefly it constructs a DatePanel instance using the default constructor which should cause it to initially show the current date. It registers itself as its own listener object and its actionPerformed() method will output the date from the DatePanel onto the terminal. The appearance of this demonstration harness was illustrated in Figures 3.7 and 3.8.

0001  // Filename DatePanelDemonstration.java. 0002  // Demonstration harness for the DatePanel. 0003  // 0004  // Written for the Java Interface book Chapter 3. 0005  // Fintan Culwin, v 0.2, August 1997. 0006   0007   0008  import java.awt.*; 0009  import java.applet.*; 0010  import java.awt.event.*; 0011   0012  import DatePanel.DatePanel; 0013   0014   0015  public class DatePanelDemonstration extends    Applet  0016                                      implements ActionListener { 0017   0018  DatePanel  aDatePanel; 0019   0020     public void init() {     0021        aDatePanel = new DatePanel(); 0022        aDatePanel.setActionCommand( "date panel demo"); 0023        aDatePanel.addActionListener( this); 0024        this.add( aDatePanel);           0025     } // End init. 0026   0027     public void actionPerformed( ActionEvent event)  {  0028        System.out.println( "Action Event received by demonstration harness."); 0029        System.out.print( "Originating from " + event.getCommandString()); 0029        System.out.println( ", " aDatePanel.yearIs()  + "/" + 0030                                 aDatePanel.monthIs() + "/" + 0031                                 aDatePanel.dayIs() + " .");                      0032     } // End actionPerformed.                        

The demonstration harness's init() method commences by creating an instance of the DatePanel class using the default constructor which should result in it displaying the current date when it first becomes visible. It registers itself as its own ActionListener on line 0023 having installed a CommandString on line 0022. Whenever the date on the panel is changed by the user a message should be output on the console, as follows, which gives an initial indication that the DatePanel seems to be working.


Action Event received by demonstration harness. 
Originating from date panel demo, 1999/12/31.

DatePanelDemonstration.java

DatePanelDemonstration


Summary of Chapter 3

3.12 The DatePanel class




A Java GUI programmer's primer
Java GUI Programmers Primer, A
ISBN: 0139088490
EAN: 2147483647
Year: 1998
Pages: 85
Authors: Fintan Culwin

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net