?? classlistenerframe.java
字號(hào):
package listener;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//對(duì)類引用ActionListener動(dòng)作接收器
public class ClassListenerFrame extends JFrame implements ActionListener {
JPanel contentPane;
JButton jButton1 = new JButton();
public ClassListenerFrame() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("對(duì)類引用事件接收器示例");
jButton1.setText("jButton1");
jButton1.setBounds(new Rectangle(112, 118, 171, 48));
jButton1.addActionListener(this);
contentPane.add(jButton1, null);
}
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
//重載動(dòng)作接收器的方法
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
( (JButton) e.getSource()).getText() + "按鈕被單擊.");
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -