下面是一个Applet程序,程序的功能是用鼠标点击画图。本题是通过点击鼠标后画出一个“Java”字。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或减行。import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code=SimpleHitMouse.java width=800 height=400></applet>*/public class SimpleHitMouse implements Applet{private java.util.Vector points=new java.util.Vector();public void init(){adclMouseListener(new MouseAdapter(){public void mousePressed(MouseEvent e){points.add(new Point (e.getX() ,e.getY()));paint ( );}});}public void update(Graphics g){repaint(g);}public void paint(Graphics g){for(int i=0;i<points.size();i++){Point dot=(Point)points.elementAt(i);g.drawString("x",dot.x,dot.y);}}public static void main(String args[ ]){Frame. fram=new Frame("CelayTree");SimpleHitMouse dot=new SimpleHitMouse();dot.init();dot.start();fram.add("Center",dot);fram.setSize(400,300);fram.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});fram.show();}}ex32_3.html:<html><head><title>A Simple Program</title></head><body><applet code="SimpleHitMouse.class" width=800 height=400></applet></body></html>
下面是一个Applet程序,程序的功能是用鼠标点击画图。本题是通过点击鼠标后画出一个“Java”字。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
注意:不改动程序的结构,不得增行或减行。
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code=SimpleHitMouse.java width=800 height=400>
</applet>
*/
public class SimpleHitMouse implements Applet{
private java.util.Vector points=new java.util.Vector();
public void init(){
adclMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
points.add(new Point (e.getX() ,e.getY()));
paint ( );
}
});
}
public void update(Graphics g){
repaint(g);
}
public void paint(Graphics g){
for(int i=0;i<points.size();i++){
Point dot=(Point)points.elementAt(i);
g.drawString("x",dot.x,dot.y);
}
}
public static void main(String args[ ]){
Frame. fram=new Frame("CelayTree");
SimpleHitMouse dot=new SimpleHitMouse();
dot.init();
dot.start();
fram.add("Center",dot);
fram.setSize(400,300);
fram.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{System.exit(0);}
});
fram.show();
}
}
ex32_3.html:
<html>
<head>
<title>A Simple Program</title>
</head>
<body>
<applet code="SimpleHitMouse.class" width=800 height=400>
</applet>
</body>
</html>