Step 3

The third step is to build the Scrollbars and a message display area. We will do this by, first, creating the scrollbars and, second, creating a TextField in which to display messages.

To simplify the discusssion, we will first include the new segments of code and then provide the complete applet, with the exception of the MyFrame class, which has not changed.

Scrollbars

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class step3 extends Applet implements AdjustmentListener {

// adds scrollbars and message display area

//****************** buildWindow
// *** Global variables for ui components
Scrollbar scrollbarV;
Scrollbar scrollbarH;

// *** build the scrollbars

scrollbarV = new Scrollbar (Scrollbar.VERTICAL, 0, 100, 0, 1000 );
scrollbarV.addAdjustmentListener ( this );
scrollbarH = new Scrollbar (Scrollbar.HORIZONTAL, 0, 100, 0, 1000 );
scrollbarH.addAdjustmentListener ( this );

//***********  Interface Methods   ***********

//****  AdjustmentListener methods

public void adjustmentValueChanged ( AdjustmentEvent e )  {
  System.out.println ( "AdjustmentEvent received" );
}

TextFields

public class step3 extends Applet implements ActionListener  {

// adds scrollbars and message display area

//****************** buildWindow
// *** Global variables for ui components

TextField message;

// *** build the message display area

message = new TextField ( "Messages Displayed Here", 80 );
message.setEditable ( false );

//***********  Interface Methods   ***********

//****  ActionListener methods

public void actionPerformed ( ActionEvent e )  {
  System.out.println ( "ActionEvent received" );
}

Complete Applet

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class step3 extends Applet implements ActionListener, AdjustmentListener {


// adds scrollbars and message display area

MyFrame outerBox;

Panel centerPanel;
Panel bottomPanel;

public void init ( ){
buildWindow ();
} // end init

//****************** buildWindow

// *** Global variables for ui components

MenuBar menuBar;

Menu fileMenu;
MenuItem neww, open, close, save, quit;

Menu editMenu;
MenuItem cut, copy, paste, delete;

Menu helpMenu;
MenuItem help;

Scrollbar scrollbarV;
Scrollbar scrollbarH;

TextField message;

private void buildWindow ( ) {

// *** Instantiate objects

outerBox = new MyFrame ( );

centerPanel = new Panel ( );
bottomPanel = new Panel ( );

// *** Build Menus

menuBar = new MenuBar ( );

fileMenu = new Menu ("File");
neww = new MenuItem ( "New" );
fileMenu.add ( neww );
neww.addActionListener ( this );
open = new MenuItem ( "Open" );
fileMenu.add ( open );
open.addActionListener ( this );
close = new MenuItem ( "Close" );
fileMenu.add ( close );
close.addActionListener ( this );
save = new MenuItem ( "Save" );
fileMenu.add ( save );
save.addActionListener ( this );
quit = new MenuItem ( "Quit" );
fileMenu.add ( quit );
quit.addActionListener ( this );

editMenu = new Menu ("Edit");
cut = new MenuItem ( "Cut" );
editMenu.add ( cut );
cut.addActionListener ( this );
copy = new MenuItem ( "Copy" );
editMenu.add ( copy );
copy.addActionListener ( this );
paste = new MenuItem ( "Paste" );
editMenu.add ( paste );
paste.addActionListener ( this );
delete = new MenuItem ( "Delete" );
editMenu.add ( delete );
delete.addActionListener ( this );

helpMenu = new Menu ("Help");
help = new MenuItem ( "Help" );
helpMenu.add ( help );
help.addActionListener ( this );

menuBar.add ( fileMenu );
menuBar.add ( editMenu );
menuBar.add ( helpMenu );
menuBar.setHelpMenu ( helpMenu );

// *** build the scrollbars

scrollbarV = new Scrollbar (Scrollbar.VERTICAL, 0, 100, 0, 1000 );
scrollbarV.addAdjustmentListener ( this );
scrollbarH = new Scrollbar (Scrollbar.HORIZONTAL, 0, 100, 0, 1000 );
scrollbarH.addAdjustmentListener ( this );

// *** build the message display area

message = new TextField ( "Messages Displayed Here", 80 );
message.setEditable ( false );

// *** build the bottom panel

bottomPanel.setLayout ( new BorderLayout ( ) );
bottomPanel.add ( "North", scrollbarH );
bottomPanel.add ( "South", message );

// *** Set colors

centerPanel.setBackground (Color.white);
bottomPanel.setBackground (Color.white);


// *** build the window

outerBox.setMenuBar ( menuBar );
outerBox.setLayout (new BorderLayout ( ) );
outerBox.add ("Center", centerPanel);
outerBox.add ("South", bottomPanel);
outerBox.add ("East", scrollbarV);
outerBox.resize (600, 500);
outerBox.setBackground (Color.white);

outerBox.addWindowListener ( outerBox );

outerBox.show( );

} // end buildWindow ()


//*********** Interface Methods ***********

//**** ActionListener methods

public void actionPerformed ( ActionEvent e ) {
System.out.println ( "ActionEvent received" );
}

//**** AdjustmentListener methods

public void adjustmentValueChanged ( AdjustmentEvent e ) {
System.out.println ( "AdjustmentEvent received" );
}


}// end step3


Run the applet