frame = new JFrame("Thread Test");
int width = (int)frame.getToolkit().getScreenSize().getWidth();
int height = (int)frame.getToolkit().getScreenSize().getHeight();
frame.setSize(width / 2, height / 2);
frame.setLocation(width / 4, height / 4);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel controlPanel = new JPanel();
frame.getContentPane().add(controlPanel, java.awt.BorderLayout.NORTH);
pause = new JButton("Pause");
pause.addActionListener(this);
controlPanel.add(pause);
resume = new JButton("Resume");
resume.setEnabled(false);
resume.addActionListener(this);
controlPanel.add(resume);
stop = new JButton("Stop");
stop.addActionListener(this);
controlPanel.add(stop);
restart = new JButton("Restart");
restart.addActionListener(this);
controlPanel.add(restart);
info = new JTextArea();
info.setEditable(false);
JScrollPane infoPanel = new JScrollPane(info);
frame.getContentPane().add(infoPanel, java.awt.BorderLayout.CENTER);
frame.setVisible(true);
ti = new ThreadInfo(this);
initThread();
}
public void initThread() {
ta = new ThreadAdd(ti);
ta.start();
td = new ThreadDel(ti);
td.start();
}
public void setInfo(String runningInfo) {
info.append(runningInfo);
}
public void disableBtn() {
pause.setEnabled(false);
resume.setEnabled(false);
stop.setEnabled(false);
}
public class ThreadInfo {
//memory size
private static final int SIZE = 10;
//running flag
public static final int RUN = 0;
public static final int PAUSE = 1;
public static final int STOP = -1;
//memory
private static List memory = null;
//memory flag
private static int flag = 0;
//running infomation
private String runningInfo = null;
//ThreadMain
private ThreadMain tm = null;