December 1999
JP219 : JAVA PROGRAMMING

QUESTION 4

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 4

 

A Frame is a derived class of the AWT component Window .Frames inherit from the Component class,and therefore components can be added using the add method.
A Button is a basic AWT component,which has a basic push to activate interface,with a title that informs the user of its use.A button can be placed in a frame.
A CheckBox is also a basic AWT component and is a simple on/off push to activate switch, is a member of a CheckBoxGroup ,has a title and is placed in a frame.

 

 
(a)

 Define a class,called MyFrame which implements a frame by extending the Frame superclass.Your class should contain a constructor which creates the frame with a named title bar.In addition to this,include in your declaration a protected button b a protected checkbox group cg and a protected checkbox c .

 

[5]
(b)

 Write a method,called MyButton ,the signature of which is given below,which is a member of your MyFrame class.The method should take two String parameters x and y ,and allocate the button b ,such that it is added to your frame,and has title x and the action command y .Your method should also ensure that the button is set up with the frames action listener component.
void MyButton(String x,String y);

 

[5]

(c)

 Write a method,called MyCheckBox ,the signature of which is given below,which is a member of your MyFrame class.The method should take a single String parameter x , and add to your frame f the check box c ,such that it has title x ,initial value true and is a member of the check box group cg .
void MyCheckBox(String x);

[5]