标签:item over public arc res ace uid out hidden
1 package com.example.test; 2 3 import java.awt.EventQueue; 4 5 import javax.swing.JFrame; 6 import javax.swing.JPanel; 7 import javax.swing.border.EmptyBorder; 8 import javax.swing.JButton; 9 import java.awt.FlowLayout; 10 import javax.swing.event.AncestorListener; 11 import javax.swing.event.AncestorEvent; 12 import javax.swing.event.ChangeListener; 13 import javax.swing.event.ChangeEvent; 14 import java.awt.event.ComponentAdapter; 15 import java.awt.event.ComponentEvent; 16 import java.awt.event.ContainerAdapter; 17 import java.awt.event.ContainerEvent; 18 import java.awt.event.FocusAdapter; 19 import java.awt.event.FocusEvent; 20 import java.awt.event.HierarchyListener; 21 import java.awt.event.HierarchyEvent; 22 import java.awt.event.HierarchyBoundsAdapter; 23 import java.awt.event.InputMethodListener; 24 import java.awt.event.InputMethodEvent; 25 import java.awt.event.ItemListener; 26 import java.awt.event.ItemEvent; 27 import java.awt.event.KeyAdapter; 28 import java.awt.event.KeyEvent; 29 import java.awt.event.MouseAdapter; 30 import java.awt.event.MouseEvent; 31 import java.awt.event.MouseMotionAdapter; 32 import java.awt.event.MouseWheelListener; 33 import java.awt.event.MouseWheelEvent; 34 import java.beans.PropertyChangeListener; 35 import java.beans.PropertyChangeEvent; 36 import java.beans.VetoableChangeListener; 37 38 public class ButtonClickTest extends JFrame { 39 40 /** 41 * 42 */ 43 private static final long serialVersionUID = 2643641337669537093L; 44 private JPanel contentPane; 45 46 /** 47 * Launch the application. 48 */ 49 public static void main(String[] args) { 50 EventQueue.invokeLater(new Runnable() { 51 public void run() { 52 try { 53 ButtonClickTest frame = new ButtonClickTest(); 54 frame.setVisible(true); 55 } catch (Exception e) { 56 e.printStackTrace(); 57 } 58 } 59 }); 60 } 61 62 /** 63 * Create the frame. 64 */ 65 public ButtonClickTest() { 66 67 68 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 69 setBounds(100, 100, 450, 300); 70 contentPane = new JPanel(); 71 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 72 setContentPane(contentPane); 73 contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); 74 75 JButton btnNewButton = new JButton("New button"); 76 btnNewButton.addVetoableChangeListener(new VetoableChangeListener() { 77 public void vetoableChange(PropertyChangeEvent evt) { 78 System.out.println("vetoableChange"); 79 } 80 }); 81 btnNewButton.addPropertyChangeListener(new PropertyChangeListener() { 82 public void propertyChange(PropertyChangeEvent evt) { 83 System.out.println("propertyChange"); 84 } 85 }); 86 btnNewButton.addMouseWheelListener(new MouseWheelListener() { 87 public void mouseWheelMoved(MouseWheelEvent e) { 88 System.out.println("mouseWheelMoved"); 89 } 90 }); 91 btnNewButton.addMouseMotionListener(new MouseMotionAdapter() { 92 @Override 93 public void mouseDragged(MouseEvent e) { 94 System.out.println("mouseDragged"); 95 } 96 @Override 97 public void mouseMoved(MouseEvent e) { 98 System.out.println("mouseMoved"); 99 } 100 }); 101 btnNewButton.addMouseListener(new MouseAdapter() { 102 @Override 103 public void mouseClicked(MouseEvent e) { 104 System.out.println("mouseClicked"); 105 } 106 @Override 107 public void mouseEntered(MouseEvent e) { 108 System.out.println("mouseEntered"); 109 } 110 @Override 111 public void mouseExited(MouseEvent e) { 112 System.out.println("mouseExited"); 113 } 114 @Override 115 public void mousePressed(MouseEvent e) { 116 System.out.println("mousePressed"); 117 } 118 @Override 119 public void mouseReleased(MouseEvent e) { 120 System.out.println("mouseReleased"); 121 } 122 }); 123 btnNewButton.addKeyListener(new KeyAdapter() { 124 @Override 125 public void keyPressed(KeyEvent e) { 126 System.out.println("keyPressed"); 127 } 128 @Override 129 public void keyReleased(KeyEvent e) { 130 System.out.println("keyReleased"); 131 } 132 @Override 133 public void keyTyped(KeyEvent e) { 134 System.out.println("keyTyped"); 135 } 136 }); 137 btnNewButton.addItemListener(new ItemListener() { 138 public void itemStateChanged(ItemEvent e) { 139 System.out.println("itemStateChanged"); 140 } 141 }); 142 btnNewButton.addInputMethodListener(new InputMethodListener() { 143 public void caretPositionChanged(InputMethodEvent event) { 144 System.out.println("caretPositionChanged"); 145 } 146 public void inputMethodTextChanged(InputMethodEvent event) { 147 System.out.println("inputMethodTextChanged"); 148 } 149 }); 150 btnNewButton.addHierarchyBoundsListener(new HierarchyBoundsAdapter() { 151 @Override 152 public void ancestorMoved(HierarchyEvent e) { 153 System.out.println("ancestorMoved"); 154 } 155 @Override 156 public void ancestorResized(HierarchyEvent e) { 157 System.out.println("ancestorResized"); 158 } 159 }); 160 btnNewButton.addHierarchyListener(new HierarchyListener() { 161 public void hierarchyChanged(HierarchyEvent e) { 162 System.out.println("hierarchyChanged"); 163 } 164 }); 165 btnNewButton.addFocusListener(new FocusAdapter() { 166 @Override 167 public void focusGained(FocusEvent e) { 168 System.out.println("focusGained"); 169 } 170 @Override 171 public void focusLost(FocusEvent e) { 172 System.out.println("focusLost"); 173 } 174 }); 175 btnNewButton.addContainerListener(new ContainerAdapter() { 176 @Override 177 public void componentAdded(ContainerEvent e) { 178 System.out.println("componentAdded"); 179 } 180 @Override 181 public void componentRemoved(ContainerEvent e) { 182 System.out.println("componentRemoved"); 183 } 184 }); 185 btnNewButton.addComponentListener(new ComponentAdapter() { 186 @Override 187 public void componentHidden(ComponentEvent e) { 188 System.out.println("componentHidden"); 189 } 190 @Override 191 public void componentMoved(ComponentEvent e) { 192 System.out.println("componentMoved"); 193 } 194 @Override 195 public void componentResized(ComponentEvent e) { 196 System.out.println("componentResized"); 197 } 198 @Override 199 public void componentShown(ComponentEvent e) { 200 System.out.println("componentShown"); 201 } 202 }); 203 btnNewButton.addChangeListener(new ChangeListener() { 204 public void stateChanged(ChangeEvent e) { 205 System.out.println("stateChanged"); 206 } 207 }); 208 btnNewButton.addAncestorListener(new AncestorListener() { 209 public void ancestorAdded(AncestorEvent event) { 210 System.out.println("ancestorAdded"); 211 } 212 public void ancestorMoved(AncestorEvent event) { 213 System.out.println("ancestorMoved"); 214 } 215 public void ancestorRemoved(AncestorEvent event) { 216 System.out.println("ancestorRemoved"); 217 } 218 }); 219 contentPane.add(btnNewButton); 220 } 221 222 }
标签:item over public arc res ace uid out hidden
原文地址:https://www.cnblogs.com/LiuYanYGZ/p/9216058.html