7.6 The CommandLineTuttleInterface class

Corresponding to the previous tuttle interfaces the CommandLineTuttle interface is provided by an instance of the CommandLineTuttle class, providing the translation layer, and an instance of the CommandLineTuttleInterface class, providing the interface presentation layer. The implementation of the CommandLineTuttleInterface class is as follows.

0001  // Filename CommandLineTuttleInterface.java. 0002  // Supplies the command line interface for   0003  // the Tuttle class. 0004  // 0005  // Written for Java Interface book chapter 7. 0006  // Fintan Culwin, v 0.2, August 1997. 0007   0008  package CommandLineTuttle; 0009   0010  import java.awt.*; 0011  import java.awt.event.*; 0012   0013  import Tuttles.TextTuttle; 0014   0015  class CommandLineTuttleInterface extends Panel {    0016   0017  private TextArea  commandFeedback; 0018  private TextField commandArea; 0019   0020     protected CommandLineTuttleInterface( ActionListener itsListener) {  0021                     0022        this.setLayout( new BorderLayout()); 0023   0024        commandFeedback = new TextArea( 6, 60); 0025        commandFeedback.setEditable( false); 0026         0027        commandArea = new TextField( 60);  0028        commandArea.addActionListener( itsListener); 0029          0030        this.add( commandFeedback, "Center"); 0031        this.add( commandArea,     "South");                 0032     } // End CommandLineTuttleInterface constructor.    0033   0034     protected void clearCommandArea() {  0035         commandArea.setText( "");    0036     } // End clearCommandArea. 0037   0038     protected void appendFeedback( String toAppend) {  0039         commandFeedback.append( toAppend);    0040     } // End clearCommandArea. 0041  } // End class CommandLineTuttleInterface class.

This interface, shown at the bottom of Figure 7.5, consists of a TextArea, called commandFeedback, mounted above a TextField, called commandArea. The constructor, on lines 0020 to 0032, constructs these two instances and mounts them as appropriate using a BorderLayout policy. The commandFeedback area is configured to be non-editable and the commandArea has the ActionListener argument of the constructor, itsListener, registered with it.

The only other methods of this class are clearCommandArea(), on lines 0034 to 0036, and appendFeedback() on lines 0038 to 0041. The clearCommandArea() method clears the contents of the lower area and the appendFeedback() method appends the String in its argument to the text displayed in the upper text area.

 


CommandLineTuttleInterface.java


7.7 The CommandLineTuttle class

7.5 The CommandLineTuttle interface




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