二级java要考swing,顺手整理了一下,记住这些可以去安逸的去做填空大题啦。
- 动作事件监听器(btn按钮
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){}
});
- 焦点事件监听器(jt文本框
jt.addFocusListener(new FocusListener(){
public void focusLost(FocusEvent e){}//失去焦点
public void focusGained(FocusEvent e){}获得焦点
});
- 键盘事件(textField
textField.addKeyListener(new KeyListener(){
public void keyTyped(KeyEvent e){}//点一下
public void keyPressed(KeyEvent e){}//长按
public void keyReleased(KeyEvent e){}//松开
});
- 鼠标事件(label
label.addMouseListener(new MouseListener){
public void mouseEntered(MouseEvent e){}//鼠标移入
public void mousePressed(MouseEvent e){}//长按
public void mouseReleased(MouseEvent e){}//松开
public void mouseClicked(MouseEvent e){}//单击
public void mouseExited(MouseEvent e){}//鼠标移出
});
- 窗体焦点事件(window(可省略)
window.addWindowFocusListener(new WindowFocusListener(){
public void windowGainedFocus(WindowEvent e);//获得焦点
public void windowLostFocus(WindowEvent e);//失去焦点
});
- 窗体状态事件(window(可省略)
window.addWindowStateListener(new WindowFocusListener(){
public void windowStateChanged(WindowEvent e){
//int oldState=e.getOldState();
//int newState=e.getNewState();
}
});
- 窗体事件
class a implements WindowListener{
public void windowActivited(WindowEvent e){};
public void windowOpened(WindowEvent e){};
public void windowIconified(WindowEvent e){};
public void windowDeiconified(WindowEvent e){};
public void windowClosing(WindowEvent e){};
public void windowDeactivated(WindowEvent e){};
public void windowClosed(WindowEvent e){};
}
- 选项事件(comboBox 下拉列表框
comboBox.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){}
});