问答题
import java.awt.*;
import java.applet.*;
*/
<applet code=ex1_3.class width=800 height=400>
</applet>
*/
public class ex1_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);
bClear = 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=" ex1_3.class" width=800 height=400 >
</applet>
</BODY>
</HTML>