标签:layout java 多线程 ini ada 而且 system ring boolean add
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"); private Button start = new Button("Start"); private TextFiled t = new TextFiled(10); private boolean runFlag = true; private long i = 0; public void int() { add(t); start.addActionListener(new StartL()); add(start); onOff.addActionListener(new onOffL()); add(onOff); } public void go() { while(true) { i = 0; while(i<=10000000000) i++; 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)/*process interface,not exceut while brower*/ { 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); } }
运行时,一旦按下start按钮,就会调用go方法,程序不能再对其它任何事件进行响应,Toggle按钮和窗口的关闭按钮不再有反应
我们期望go()继续执行自己的操作,而于此同时,它也需要返回,以便actionPerformed()能够完成,而且用户界面也能继续响应用户操作
即线程的作用
标签:layout java 多线程 ini ada 而且 system ring boolean add
原文地址:http://www.cnblogs.com/gride-glory/p/7774936.html