READINGS
(Top)
PROBLEMS
(Top)
public class NumbPad extends Frame
{
....
public NumbPad()
{
//Construct superclass with title
super("Numeric Keypad");
//Create grid bag layout
GridBagLayout grid = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
//Set frame layout to grid bag
this.setLayout(grid);
//Assume all have equal weight
gbc.weightx = 100.0;
gbc.weighty = 100.0;
gbc.fill = GridBagConstraints.BOTH;
//Make enter and clear X Y W H
buttonClr = makeButton("Clear", grid,gbc,0,0,1,1);
buttonEnter = makeButton("Enter", grid,gbc,3,3,1,2);
//Pad width to approximate width of Clear
gbc.ipadx = 50;
//Create operations X Y W H
buttonDiv = makeButton("/",grid,gbc,1,0,1,1);
buttonMul = makeButton("*",grid,gbc,2,0,1,1);
buttonSub = makeButton("-",grid,gbc,3,0,1,1);
buttonSub = makeButton("+",grid,gbc,3,1,1,2);
buttonDot = makeButton(".",grid,gbc,2,4,1,1);
//Make digits
button0 = makeButton("0",grid,gbc,0,4,2,1);
button1 = makeButton("1",grid,gbc,0,3,1,1);
button2 = makeButton("2",grid,gbc,1,3,1,1);
button3 = makeButton("3",grid,gbc,2,3,1,1);
button4 = makeButton("4",grid,gbc,0,2,1,1);
button5 = makeButton("5",grid,gbc,1,2,1,1);
button6 = makeButton("6",grid,gbc,2,2,1,1);
button7 = makeButton("7",grid,gbc,0,1,1,1);
button8 = makeButton("8",grid,gbc,1,1,1,1);
button9 = makeButton("9",grid,gbc,2,1,1,1);
//Resize and validate
this.resize(200,250);
this.validate();
}
Write a Java class called MainWindow that extends Frame to implement this interface. Assume that the main display is a text area that uses the monospaced Courier font. The main display should get all of the additional height if the window is resized. Include a main() method that can be used to quickly test the appearance of the interface.
EXERCISES
(Top)
Your work on these exercises will be very useful for the second graded problem.
Study the code to be sure you understand how an instance of this class would be constructed and used. The comments in the code conform to the Java Documentation Comment Syntax which means that you can run the javadoc utility against the class to produce an html document file. The command is:
javadoc FormGridLayout.java
If you view the resulting html file in the browser, you can read
the formatted documentation but you will be missing all of the
images for the various colored balls and headings that appear
in web based documentation.
You can, of course, copy these images from the CD-ROM and put them in the appropriate directory if you really want pretty documentation.
Prepared by David L. March -- Last Revised on October 10, 1998
COPYRIGHT © 1998 BY DAVID L. MARCH