📄 counter.java
字号:
import java.awt.*;import java.awt.event.*;import java.applet.*;public class Counter extends Applet { private int count = 0; private Button onOff = new Button("Stop count"), start = new Button("Start count"); private TextField t = new TextField(10); private boolean runFlag = true; public void init() { add(t); start.addActionListener(new StartL()); add(start); onOff.addActionListener(new OnOffL()); add(onOff); } public void go() { while(true) { try { Thread.currentThread().sleep(100); } catch(InterruptedException ie) { if(runFlag) { t.setText(Integer.toString(count++)); } } } } class StartL implements ActionListener { public void actionPerformed(ActionEvent e) { go(); } } class OnOffL implements ActionListener { public void actionPerformed(ActionEvent e) { runFlag = !runFlag; } } public static void main(String[] args) { Counter applet = new Counter(); Frame aFrame = new Frame("Counter"); aFrame.addWindowListener (new WindowAdapter(){ public void windowClosing(WindowEvent e) { System.exit(0); } }); aFrame.add(applet, BorderLayout.CENTER); aFrame.setSize(300, 200); applet.init(); applet.start(); aFrame.setVisible(true); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -