CT038-3-2 Object Oriented Development With Java
CT038-3-2 Object Oriented Development With Java
Java GUI
Topic & Structure of the lesson
GUI
Event Listener
Applet
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
// An action listener that prints a message.
public class ClickListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
System.out.println(I was clicked.);
}
}
/**
This program demonstrates how to install an action listener.
*/
public class ButtonTester
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
JButton button = new JButton("Click me!");
frame.add(button);
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
Example:
Lets study a simple investment viewer
program that puts a button to work.
Whenever the button is clicked, interest is
added to a bank account, and the new
balance is displayed.
</APPLET>