public class Frame1 extends JFrame implements MouseListener{
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JButton jButton1 = new JButton();
JPanel jPanel1 = new JPanel();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setText("jButton1");
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
contentPane.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jButton1, null);
jButton1.addMouseListener(this);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
/**
* Invoked when the mouse button has been clicked (pressed
* and released) on a component.
*/
public void mouseClicked(MouseEvent e)
{
System.out.println("mouseClicked");
}
/**
* Invoked when a mouse button has been pressed on a component.
*/
public void mousePressed(MouseEvent e)
{
System.out.println("mousePressed");
}
/**
* Invoked when a mouse button has been released on a component.
*/
public void mouseReleased(MouseEvent e)
{
System.out.println("mouseReleased");
}
/**
* Invoked when the mouse enters a component.
*/
public void mouseEntered(MouseEvent e)
{
System.out.println("mouseEntered");
}
/**
* Invoked when the mouse exits a component.
*/
public void mouseExited(MouseEvent e)
{
System.out.println("mouseExited");
}
public static void main(String args[])
{
Frame1 frame = new Frame1();