Do not award half marks.
Do not deduct marks for trivial syntactic errors. Alternative correct
answers should be given credit, unless otherwise indicated in the
marking scheme.
(a)Briefly explain the major differences between the AWT library
and the Swing library.[2 marks ]
Swing components are implemented with absolutely no native code;(1
mark)
This feature gives Swing components more functionality than
AWT components. (1 mark)
[2 marks ]
(b)(i)Define a class,called FrameClass which extends the JFrame superclass.Your
class should contain a constructor which creates the frame with a
named title bar.[3 marks ]
(ii)Define a method,called main which is a member of the class FrameClass
which creates an object of type FrameClass with My Swing Application
as the title.The member methods of the JFrame class should then set
the size of the frame to 100 by 200 pixels,and display the frame.[4
marks ]
(iii)Write the statements (which could be added to your main function)
necessary to declare and add a JButton to the north of the frame,using
a BorderLayout manager.The title of the button should read Press
Me!.
public void MyButtonAdd(); [4 marks ]
(iv)Give the statements necessary to ensure that the AWT and Swing
packages
would be correctly made available to your class.[2 marks ]
(i)A
sample definition of FrameClass follows:
public class FrameClass extends JFrame {
public FrameClass(String title) {
super(title);
}
}
And the following marking scheme should be used:
Correctly extending the JFrame class;(1 mark)
A correct constructor,with correct parameter;(1 mark)
Correctly initialising the base class title by calling super
(1 mark)
[3 marks ]
(ii)A sample definition of main follows:
public static void main(String[] args) {
FrameClass fr= new FrameClass(My Swing Application);
fr.setSize(100, 200);
fr.setVisible(true);
}
And the following marking scheme should be used:
Correctly declaring the object fr with correct type;(1 mark)
Correctly calling the constructor with the correct string argument;(1
mark)
Correctly calling and using setSize (1 mark)
Correctly calling and using setVisible (1 mark)
[4 marks ]
(iii)A sample definition ofthe statements
follows:
JButton jb= new JButton(Press Me!);
fr.getContentPane().add(jb, BorderLayout.NORTH);
And the following marking scheme should be used:
Correctly declaring the object jb with the correct type;(1 mark)
Correctly initialising the button with the title Press
Me!;(1 mark)
Correctly adding the button to the panel using fr.getContentPane.add();
(1 mark)
Correctly positioning the button in the north using the Borderlayout
manager.(1 mark)
[4 marks ]
(iv) import javax.swing.*; (1 mark)
import java.awt.*; (1 mark)
[2 marks ]
|