import javax.swing.*; import java.awt.*; public class Head extends JFrame{ private JTextArea textArea = new JTextArea(); public Head(String title){ super(title); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); getContentPane().add(scrollPane, BorderLayout.CENTER); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(500, 400); show(); doIt(); } public void doIt(){ Thread current = Thread.currentThread(); int counter = 0; ThreadOne one = null; RunnableTwo two = null; boolean alive = true; while(alive){ try { current.sleep(1000); } catch(InterruptedException ie) { } switch (counter){ case 0:{ textArea.append("\nCreating and starting thread 1\n\n"); textArea.setCaretPosition(textArea.getText().length()); one = new ThreadOne(textArea); }break; case 5:{ textArea.append("\nCreating and starting thread 2\n\n"); textArea.setCaretPosition(textArea.getText().length()); two = new RunnableTwo(textArea); }break; case 10:{ two.pause(); textArea.append("\nPausing thread 2\n\n"); textArea.setCaretPosition(textArea.getText().length()); }break; case 15:{ textArea.append("\nRestarting thread 2\n\n"); textArea.setCaretPosition(textArea.getText().length()); two.restart(); }break; case 20:{ one.kill(); textArea.append("\nKilling thread 1\n\n"); textArea.setCaretPosition(textArea.getText().length()); }break; case 25:{ two.kill(); textArea.append("\nKilling thread 2\n\n"); textArea.setCaretPosition(textArea.getText().length()); alive = false; } } counter++; } } public static void main(String[] args){ new Head("ThreadTester"); } }