⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 counter1.java

📁 java 数据结构的一些简单实例和一些线程的应用主要是面向初学者
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class Counter1 extends Applet {
private int count=0;
private Button
onoff=new Button("toggle"),
start=new Button("start");
private TextField t=new TextField(10);
private boolean runflag=true;

public void init(){
	add(t);
	start.addActionListener(new start());
	add(start);
	start.addActionListener(new onoff());
	add(onoff);
}
public void go(){
	while(true){
             try{
            	Thread.currentThread().sleep(100);
             }catch(InterruptedException e){}
             if(runflag)
             t.setText(Integer.toString(count++));
	}
}

class start implements ActionListener{
	public void actionPerformed(ActionEvent e){
		go();
	}
	
}
class onoff implements ActionListener{
	public void actionPerformed(ActionEvent e){
		runflag=!runflag;
	}
}

public static void main(String[] args){
	Counter1 applet=new Counter1();
	Frame aFrame=new Frame("counter1");
	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 + -