EventObjectWindow.java - import javax.swing/Needed for...

This preview shows page 1 - 2 out of 2 pages.

import javax.swing.*; //Needed for Swing classes import java.awt.event.*; //Needed for event listener interface public class EventObjectWindow extends JFrame { /** This class demonstrates how to retrieve the action command from an event object */ private JButton button1; private JButton button2; private JButton button3; private JPanel panel; //A panel to hold components private final int WINDOW_WIDTH = 300; private final int WINDOW_HEIGHT = 70; public EventObjectWindow() //Constructor { //Set the title bar text setTitle("Event Object Demonstration"); //Set the size of the window setSize(WINDOW_WIDTH, WINDOW_HEIGHT); //Specify what happens when the close button is clicked setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create the three buttons button1 = new JButton("Button 1"); button2 = new JButton("Button 2"); button3 = new JButton("Button 3"); //Register an event listener with all 3 buttons button1.addActionListener(new ButtonListener()); button2.addActionListener(new ButtonListener()); button3.addActionListener(new ButtonListener());

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture