/** * NoThread.java (it does not create any new threads). * But it would be nice to create one (see the next example: SimpleThread1.java) * Best run in appletviewer to see the full effect of a greedy thread. * With the present version try resizing and iconifying and * de-iconifying: strange results. */ import java.awt.*; import java.applet.Applet; import java.awt.event.*; public class NoThread extends Applet implements ActionListener { private TextArea ta; private Panel pnl; private Button btnGo, btnStop; private final long max = 4000; private boolean counting ; public void init() { ta = new TextArea(16, 50); add(ta); pnl = new Panel(); btnGo = new Button("GO"); btnStop = new Button("STOP"); pnl.add(btnGo); pnl.add(btnStop); add(pnl); btnGo.addActionListener(this); btnStop.addActionListener(this); } public void lotsOfNumbers(long biggest) { ta.setText(""); for(long i = 0; i < biggest; i++) { if((i % 10) == 0) ta.append("\n"); ta.append(String.valueOf(i) ); ta.append(" "); if(!counting) break; } } public void actionPerformed(ActionEvent aevt) { if(aevt.getActionCommand().equals("GO")) { counting = true; lotsOfNumbers(max); } if(aevt.getActionCommand().equals("STOP")) { counting = false; } } public void destroy() { counting = false; ta.setText(""); ta = null ; } }