clickme.java
来自「java语言与面向对象程序设计源程序」· Java 代码 · 共 35 行
JAVA
35 行
import java.awt.*;
import java.awt.event.*;
public class ClickMe extends Frame implements ActionListener
{ // 定义域
private Button quit = new Button("Quit");
private Button click = new Button("Click here");
private TextField text = new TextField(10);
private boolean secondClick = false;
//定义构造函数
public ClickMe()
{ super("Click Example");
setLayout(new FlowLayout());
add(quit); add(click);
click.addActionListener(this);
quit.addActionListener(this);
add(text);
pack(); show();
}
// 定义方法
public void actionPerformed(ActionEvent e)
{ if (e.getSource() == quit)
System.exit(0);
else if (e.getSource() == click)
{ if (secondClick)
text.setText("not again !");
else
text.setText("Uh, it tickles");
secondClick = !secondClick;
}
}
public static void main(String args[])
{ ClickMe myFrame = new ClickMe(); }
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?