You are on page 1of 2

import java.awt.

*;
import java.awt.event.*;
public class Bai3 extends Frame {

private HighThread high;


private LowThread low;
private TextArea output;

public Bai3()
{
super("Bai 3");
output = new TextArea(10,20);
add(output);
setSize(250,200);
setVisible(true);
high = new HighThread(output);
high.start();
low = new LowThread(output);
low.start();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Bai3 b3 = new Bai3();
b3.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
class HighThread extends Thread
{
private TextArea display;
public HighThread(TextArea a)
{
display = a;
setPriority(Thread.MAX_PRIORITY);
}
public void run()
{
for (int i=1;i<=5;i++)
{
display.append("High\n");
}
}
}

class LowThread extends Thread


{
private TextArea display;
public LowThread(TextArea a)
{
display = a;
setPriority(Thread.MIN_PRIORITY);
}
public void run()
{
for (int i=1;i<=5;i++)
{
display.append("Low\n");
}
}
}

You might also like