【说明】
下面是一个Applet程序,其功能是将完整的图像显示于Applet的区块中,然后可以通过拖动鼠标让图像随着鼠标拖动的轨迹而移动。
程序运行结果如图5所示。
import java. applet. *;
import java. awt. *;
/*
<applet code="ex4_7.class",width=800 height=400>
</applet>
*/
public class ex4_7 extends Applet
private |mage ilmg;
private int xPos,yPos;
public void init()
xPos = yPos= (1) ;
ilmg=getlmage( (2) "ex4_7.jpg");
publicvoid paint(Graphics g)
g. drawlmage(ilmg,xPos,yPos, (3) );
public boolean (4) (Evente,int x,int y)
xPos=x;
yPos=y;
(5) ;
return true;
ex4_7. html
<HTML>
<HEAD>
<TITLE> ex4_7 </TITLE>
</HEAD>
<BODY>
<appletcode=" ex4_7. class" width =800 height =400 >
</applet>
</BODY>
</HTML>