package com.example.test; import java.awt.EventQueue; import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.FlowLayout;
import javax.swing.event.AncestorListener;
import javax.swing.event.AncestorEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ContainerAdapter;
import java.awt.event.ContainerEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.HierarchyListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyBoundsAdapter;
import java.awt.event.InputMethodListener;
import java.awt.event.InputMethodEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseWheelListener;
import java.awt.event.MouseWheelEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.beans.VetoableChangeListener; public class ButtonClickTest extends JFrame { /**
*
*/
private static final long serialVersionUID = 2643641337669537093L;
private JPanel contentPane; /**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ButtonClickTest frame = new ButtonClickTest();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} /**
* Create the frame.
*/
public ButtonClickTest() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); JButton btnNewButton = new JButton("New button");
btnNewButton.addVetoableChangeListener(new VetoableChangeListener() {
public void vetoableChange(PropertyChangeEvent evt) {
System.out.println("vetoableChange");
}
});
btnNewButton.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
System.out.println("propertyChange");
}
});
btnNewButton.addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent e) {
System.out.println("mouseWheelMoved");
}
});
btnNewButton.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
System.out.println("mouseDragged");
}
@Override
public void mouseMoved(MouseEvent e) {
System.out.println("mouseMoved");
}
});
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("mouseClicked");
}
@Override
public void mouseEntered(MouseEvent e) {
System.out.println("mouseEntered");
}
@Override
public void mouseExited(MouseEvent e) {
System.out.println("mouseExited");
}
@Override
public void mousePressed(MouseEvent e) {
System.out.println("mousePressed");
}
@Override
public void mouseReleased(MouseEvent e) {
System.out.println("mouseReleased");
}
});
btnNewButton.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
System.out.println("keyPressed");
}
@Override
public void keyReleased(KeyEvent e) {
System.out.println("keyReleased");
}
@Override
public void keyTyped(KeyEvent e) {
System.out.println("keyTyped");
}
});
btnNewButton.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
System.out.println("itemStateChanged");
}
});
btnNewButton.addInputMethodListener(new InputMethodListener() {
public void caretPositionChanged(InputMethodEvent event) {
System.out.println("caretPositionChanged");
}
public void inputMethodTextChanged(InputMethodEvent event) {
System.out.println("inputMethodTextChanged");
}
});
btnNewButton.addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
@Override
public void ancestorMoved(HierarchyEvent e) {
System.out.println("ancestorMoved");
}
@Override
public void ancestorResized(HierarchyEvent e) {
System.out.println("ancestorResized");
}
});
btnNewButton.addHierarchyListener(new HierarchyListener() {
public void hierarchyChanged(HierarchyEvent e) {
System.out.println("hierarchyChanged");
}
});
btnNewButton.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
System.out.println("focusGained");
}
@Override
public void focusLost(FocusEvent e) {
System.out.println("focusLost");
}
});
btnNewButton.addContainerListener(new ContainerAdapter() {
@Override
public void componentAdded(ContainerEvent e) {
System.out.println("componentAdded");
}
@Override
public void componentRemoved(ContainerEvent e) {
System.out.println("componentRemoved");
}
});
btnNewButton.addComponentListener(new ComponentAdapter() {
@Override
public void componentHidden(ComponentEvent e) {
System.out.println("componentHidden");
}
@Override
public void componentMoved(ComponentEvent e) {
System.out.println("componentMoved");
}
@Override
public void componentResized(ComponentEvent e) {
System.out.println("componentResized");
}
@Override
public void componentShown(ComponentEvent e) {
System.out.println("componentShown");
}
});
btnNewButton.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
System.out.println("stateChanged");
}
});
btnNewButton.addAncestorListener(new AncestorListener() {
public void ancestorAdded(AncestorEvent event) {
System.out.println("ancestorAdded");
}
public void ancestorMoved(AncestorEvent event) {
System.out.println("ancestorMoved");
}
public void ancestorRemoved(AncestorEvent event) {
System.out.println("ancestorRemoved");
}
});
contentPane.add(btnNewButton);
} }