✔ 最佳答案
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class Marble extends Applet {
final int MAX=10;
int[] xp, yp;
int count;
public void init(){
xp = new int[MAX];
yp = new int[MAX];
count = 0;
MsListener mouseListener=new MsListener();
setBackground(Color.white);
addMouseListener(mouseListener);
}
class MsListener extends MouseAdapter{
public void mouseClicked(MouseEvent e){
if (count < MAX) {
xp[count] = e.getX();
yp[count] = e.getY();
count++;
}
repaint();
}
}
public void paint(Graphics g){
final int WIDTH=200,HEIGHT=200;
g.draw3DRect(0,0,WIDTH-2,HEIGHT-2,false);
for(int i=0;i<count;i++){
g.setColor(Color.blue);
g.fillOval(xp[i]-5,yp[i]-5,10,10);
}
}
}
2010-12-02 17:21:04 補充:
再有功課問題可以直接寫信問我丫^^