プロセスとは、独自のアドレス空間を持つ「自己完結型」の実行プログラムを指します。スレッドは、プロセス内の単一の順次制御フローです。プロセスの特性に基づいて、コンピュータは同時に2つ以上のプログラムを実行できます。スレッドベースのマルチタスク環境では、スレッドは最小の処理単位です。
import java.awt.*;
import java.awt.event.*;
public class Javase_61 extends Frame implements ActionListener
{
static Javase_61 frm=new Javase_61 ();
static Button bnt1 =new Button("画圆");
static Button bnt2 =new Button("画椭圆");
int circle=0;
public static void main(String[] args)
{
frm.setTitle("简单绘图应用程序");
frm.setSize(300,250);
frm.setLayout(null);
bnt1.setBounds(90, 215,50,25);
bnt2.setBounds(160,215,50,25);
frm.add(bnt1); frm.add(bnt2);
bnt1.addActionListener(frm);
bnt2.addActionListener(frm);
frm.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Button bt=(Button)e.getSource(); //获取被按下的按钮
if (bt==bnt1) circle=1; //若按下的是“画圆”按钮
else circle=2; //若按下的是“画椭圆”按钮
Graphics g=getGraphics(); //获取窗口的绘图区
paint(g);
}
public void paint(Graphics g)
{
g.setFont(new Font("楷体",Font.ITALIC,20)); //设置字体
g.setColor(Color.red); //设置颜色
g.drawString("画圆或椭圆",120,50); //以(120,50)为左下角显示字符串
if (circle==1) g.drawOval (100,90,70,70); //画圆
else if (circle==2) g.drawOval (80,60,70,120); //画椭圆
}
}