网友您好, 请在下方输入框内输入要搜索的题目:
在以下程序中,鼠标单击小应用程序的某一点,则会在该点显示一个图标,如果双击,则会清除该图标。且在浏览器的状态栏上会显示鼠标单击位置的坐标。运行结果如下图所示。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
注意:不改动程序的结构,不是增行或删行。
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Example3_1 extends Applet
{
int xPoint, yPoint;
int sum;
Image displayIm;
public void init()
{
displayIm = getImage("ms.jpg");
addMouseListener(new SClickMouse()) ;
sum = 2;
}
public void paint(Graphics g)
{
if(sum == 1)
g.drawImage(displayIm, xPoint, yPoint, this);
else
g.fillRect(xPoint, yPoint, 60, 60);
}
public class SClickMouse implements MouseListener
{
public void mouseClicked(MouseEvent mouse)
{
sum = mouse.getClickCount();
xPoint = mouse.getX();
yPoint = mouse.getY();
paint();
}
public void mouseEntered(MouseEvent mouse)
{
}
public void mouseExited(MouseEvent mouse)
{}
public void mousePressed(MouseEvent mouse)
{
xPoint = mouse.getX();
yPoint = mouse.getY();
showStatus("x="+xPoint+",y-"+yPoint);
}
public void mouseReleased(MouseEvent mouse)
}
}
}
}
Exampie3_1.html:
<html>
<head><title>Example3_1</title></head>
<body>
<applet code="Example3_1.class" width="400" height="500">
</applet>
</body>
</html>
参考答案