Page 221 - CTS - CSA TP - Volume 2
P. 221
COMPUTER SOFTWARE APPLICATION - CITS
frame.getContentPane().add(button);
frame.setSize(300, 150);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Output:
TASK 3: Creating a container with controls (TextField, Button) using AWT in Java, along with action
listeners and event handlers
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
public class AwtContainerWithListeners {
public static void main(String[] args) {
// Creating the main frame
Frame frame = new Frame(“AWT Container with Listeners”);
frame.setSize(300, 150);
// Creating components
Label nameLabel = new Label(“Name:”);
TextField nameTextField = new TextField(20);
Button submitButton = new Button(“Submit”);
206
CITS : IT & ITES - Computer Software Application - Exercise 118 CITS : IT & ITES - Computer Software Application - Exercise 118