?? buttontest.java
字號:
import java.awt.*;
import java.awt.event.*;
class ButtonTest extends Frame implements ActionListener
{
TextField tf=new TextField(20);
Button btn1=new Button("Left");
Button btn2=new Button("Right");
public ButtonTest(String title)
{
super(title);
btn1.setActionCommand("b1");
btn1.addActionListener(this);
btn2.setActionCommand("b2");
btn2.addActionListener(this);
setLayout(new FlowLayout());
add(tf);
add(btn1);
add(btn2);
setSize(200,150);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
/*
if(e.getActionCommand().equals("b1"))
tf.setText("你按了Left按紐!");
else if(e.getActionCommand().equals("b2"))
tf.setText("你按了Right按紐!");
*/
/*
Button b=(Button)e.getSource();
if(b==btn1)
tf.setText("你按了Left按紐!");
else if(b==btn2)
tf.setText("你按了Right按紐!");
*/
Button b=(Button)e.getSource();
if(b.getLabel().equals("Left"))
tf.setText("你按了Left按紐!");
else if(b.getLabel().equals("Right"))
tf.setText("你按了Right按紐!");
}
public static void main(String args[])
{
new ButtonTest("按鈕示例");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -