?? actioneventdemo.java
字號:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ActionEventDemo extends JFrame implements ActionListener
{
JButton btnFirst,btnSecond;
JPanel pnlMain;
JLabel lblInfo;
public ActionEventDemo()
{
pnlMain=new JPanel();
btnFirst=new JButton("隱藏按鈕1");
btnFirst.addActionListener(this);
btnSecond=new JButton("禁用按鈕2");
btnSecond.addActionListener(this);
lblInfo=new JLabel("");
setContentPane(pnlMain);
pnlMain.add(btnFirst);
pnlMain.add(btnSecond);
pnlMain.add(lblInfo);
setSize(250,150);
setTitle("動作事件演示");
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btnFirst)
{
btnFirst.setVisible(false);
btnSecond.setEnabled(true);
lblInfo.setText(ae.getActionCommand());
}
if(ae.getSource()==btnSecond)
{
btnFirst.setVisible(true);
btnSecond.setEnabled(false);
lblInfo.setText("按鈕2不可用");
}
}
public static void main(String args[])
{
new ActionEventDemo();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -