Page 203 - CTS - CSA TP - Volume 2
P. 203
COMPUTER SOFTWARE APPLICATION - CITS
EXERCISE 116 : Create a simple container using Frame
class and extending another Frame class
Objectives
At the end of this exercise you shall be able to
• develop Java programs to Create a simple container using Frame class and extending another Frame
class
Requirements
Tools/Materials
• PC/Laptop with Windows OS
• JDK Software
• Text Editor (Visual Studio/Sublime/Notepad)
Procedure
TASK 1: Simple Frame : a simple graphical window (frame) with a label
import java.awt.Frame;
import java.awt.Label;
public class SimpleContainer extends Frame {
public SimpleContainer(String title) {
// Call the constructor of the superclass (Frame) with the specified title
super(title);
// Create a label to add to the frame
Label label = new Label(“Hello, I’m a simple container!”);
// Add the label to the frame
add(label);
// Set the size of the frame
setSize(300, 200);
// Make the frame visible
setVisible(true);
}
188