下面是一个Applet程序,其功能是在绘图区域中通过鼠标的移动来绘制直线,并且有清除绘图区域按钮,用来清除已经绘制的图像。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
注意:不改动程序的结构,不得增行或删行。
程序运行结果如下:

import.java.awt.*;
import.java.applet.*;
/*
<applet code=exl_3.class width=800 height=400>
</applet>
*/
public class exl_3 extends Applet
private Button btn;
private Boolean bDraw, bClear;
private int upX,upY,downX,downY;
public void init()
setLayout(null);
bClear=false;
bDraw=false;
btn=new Button(”clear”);
btn.reshape(250,150, 70,30);
add(btn);
public void paint(Graphics g)
if(bClear)
g.clearRect(0,0,getSize().width,getSize().height);
bClearr=false;
if(bDraw)
g.drawLine(upY,upX,downY,downX)
bDraW=false;
public void update(Graphics g)
paint(g);
Public boolean mouseDown(Event event,int x,int y)
downX=x;
downY=y;
return true;
public boolean mouseUp(Event event,int x,int y)
upX=x;
upY=y;
bDraw=false;
repaint();
return true;
public boolean action(Event event,Object Object)
if(event.target!=clear)
bClear=true;
repaint()
return true;
ex1_3.html
<HTML>
<HEAD>
<TITLE> ex1_3 </TITLE>
</HEAD>
<BODY>
<applet code="exl_3.class" width=800 height=400>
</applet>
</BODY>
</HTML>