Answer Assignment 5 -OOP II
Answer Assignment 5 -OOP II
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public ButtonEvent() {
// Set up the frame
setTitle("Button Event Demo");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
// Create buttons
addButton = new JButton("ADD");
subtractButton = new JButton("SUBTRACT");
multiplyButton = new JButton("MULTIPLY");
divideButton = new JButton("DIVIDE");
// Register listeners
addButton.addActionListener(this);
subtractButton.addActionListener(this);
multiplyButton.addActionListener(this);
divideButton.addActionListener(this);
}
public ColorChangeApplet() {
setTitle("Color Change App");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}