?? buttonexample.java
字號:
import java.awt.*;
import java.awt.event.*;
class ButtonExample
extends WindowAdapter
implements ActionListener {
Frame f;
Button b;
TextField tf;
int tag = 0;
public static void main(String args[]) {
ButtonExample be = new ButtonExample( );
be.go( );
}
public void go( ) {
f = new Frame("ButtonExample");
b = new Button("Sample");
b.addActionListener(this);
f.add(b,"South");
tf = new TextField( );
f.add(tf,"Center");
f.addWindowListener(this);
f.setSize(300,150);
f.setVisible(true);
}
// 實現ActionListener接口中的actionPerformed( )方法
public void actionPerformed(ActionEvent e) {
String s1 = "You have pressed the Button!";
String s2 = "You do another time!";
if (tag==0) {
tf.setText(s1);
tag = 1;
} else {
tf.setText(s2);
tag = 0;
}
}
// 覆蓋WindowAdapter類中的windowClosing( )方法
public void windowClosing(WindowEvent e){
// 結束程序運行
System.exit(0);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -