import javax.swing.*; import java.awt.*; public class Head extends JApplet implements Runnable{ private JTextArea textArea = new JTextArea(); private Thread thread = new Thread(this); public void init() { JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); getContentPane().add(scrollPane, BorderLayout.CENTER); thread.start(); } public void run(){ int counter = 0; ThreadOne one = null; RunnableTwo two = null; boolean alive = true; while(alive){ try { thread.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++; } } }