java.awt.Component中 repaint(int x, int y, int width, int height) 方法为 重绘组件的指定矩形区域。
请各位指点下它的具体作用是什么?如果是图像重绘的话,重绘的图像是哪个?在哪添加待显示的图像?
请高手最好留个简单代码,学习下,谢谢!!!
------解决方案--------------------
[code=Java][/code]import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TestMouseMotion {
public static void main(String args[]) {
new MyFrame88("drawing...");
}
}
class MyFrame88 extends Frame {
ArrayList<Point> points = null;
MyFrame88(String s) {
super(s);
points = new ArrayList<Point>();
setLayout(null);
setBounds(300,300,400,300);
this.setBackground(new Color(204,204,255));
setVisible(true);
System.out.println("good");
this.addMouseListener(new Monitor());
System.out.println("beter");
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void paint(Graphics g) {
Iterator<Point> i = points.iterator();
while(i.hasNext()){
Point p = (Point)i.next();
g.setColor(Color.BLUE);
g.fillOval(p.x,p.y,10,10);
}
}
public void addPoint(Point p){
points.add(p);
}
}
class Monitor extends MouseAdapter {
// private int num = 0;
public void mouseClicked(MouseEvent e) {
MyFrame88 f = (MyFrame88)e.getSource();
f.addPoint(new Point(e.getX(),e.getY()));
// if(num++ >= 5){
// f.repaint();
// num=0;
// }
}
}