August 1999
JP219 : JAVA PROGRAMMING

QUESTION 4

Total Marks: 20 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 4

(a) The Java Abstract Windowing Toolkit (AWT) provides the basic Graphical User Interface components which are used in Java applets and applications. Every GUI component that appears on the screen is a subclass of the class Component. There are two major types of components - window and panel.

(i) In the context of the AWT package, describe what is meant by a window.

(ii) In the context of the AWT package, describe what is meant by a panel.

 





[2]


[2]

(b) (i) Identify the purpose of a layout manager with respect to components.

(ii) Although it is possible to turn off the layout manager when positioning or sizing components, this is not usually advisable. State one reason why this is not usually advisable.

(iii) Briefly suggest a better method which may be employed.

 

[2]

[1]

 

[1]

(c) A Frame is a subclass of a window, with the following properties:
  • They have a title, and resize corners;
  • Inherit from Component, and add components with the add method;
  • Can be used to create invisible Frame objects, with a title specified by String;
  • Have Border Layout as the default layout manager.

(i) Define a class FooFrame, which implements a frame, by extending the frame superclass. Your class should contain a constructor function which creates the frame with a named title bar.

(ii) Define a function main, which is a member of the class FooFrame, which creates an object of type FooFrame with the title "My Frame!" , and using member functions in the Frame superclass, will set the size of the frame to 100 by 100 pixels, and will display the frame.

(iii) Write a function called AddPanel, which is called with an argument fr of type Frame, and will create a Panel, dimensions 20 * 20, and add it to the frame fr.

 

 

 

 

 


[4]

 

[4]

 

[4]