package class4_1_Singleton_eventlogger; import javax.swing.JButton; import javax.swing.JFrame; import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class UIWindow extends JFrame implements ActionListener { private String title; /** * create a dirt-simple window containing a JButton * @param title the window title */ public UIWindow( String title ) { this.title = title; // create the containing window and set its size etc setTitle(title); setSize(300, 200); setLocation(400, 400); setResizable(false); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Retrieves the window's contentPane and sets the background color to white Container contentPane = getContentPane(); // contentPane.setLayout(null); contentPane.setBackground(Color.WHITE); //Creation of "DoSomething" button JButton doButton; doButton = new JButton ("Do Something"); doButton.setActionCommand("doit"); doButton.setBounds(10, 130, 170, 30); doButton.addActionListener(this); // subscribe to events contentPane.add(doButton); contentPane.validate(); contentPane.repaint(); } @Override /** * override of ActionListener interface implemented by this class; * listens for the JButton press and logs a dumb message using the EventLogWriter. */ public void actionPerformed(ActionEvent event) { System.out.println(title + ": in actionPerformed()"); // Write the message // Note: calls getInstance on the event-dispatch thread EventLogWriter.getInstance().logEvent(title + " an event occurred"); } }