// This example is from the book _Java in a Nutshell_ by David Flanagan.
// Written by David Flanagan. Copyright (c) 1996 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or implied.
import java.applet.*;
import java.awt.*;
import java.io.*;
public class AppletThreadLister extends Applet {
TextArea textarea;
// Create a text area to put our listing in
public void init() {
textarea = new TextArea(20, 60);
this.add(textarea);
Dimension prefsize = textarea.preferredSize();
this.resize(prefsize.width, prefsize.height);
}
// Do the listing. Note the cool use of ByteArrayOutputStream.
public void start() {
ByteArrayOutputStream os = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(os);
ThreadLister.listAllThreads(ps);
textarea.setText(os.toString());
}
}
|