import java.awt.*;import java.awt.event.*;
import java.util.*;class MyLine
{
private int x1;
private int y1;
private int x2;
private int y2;
public MyLine(int x1,int y1,int x2,int y2)
{
this.x1=x1;
this.y1=y1;
this.x2=x2;
this.y2=y2;
}
public void drawMe(Graphics g)
{
g.drawLine(x1,y1,x2,y2);
}}public class RedrawAllLine extends Frame{ private static final long serialVersionUID = 1L;
Vector<MyLine> vLines=new Vector<MyLine>();
public static void main(String[] args) {
// TODO Auto-generated method stub
RedrawAllLine f=new RedrawAllLine();
f.init();
}
public void paint(Graphics g)
{
g.setColor(Color.red);

Enumeration<MyLine> e=vLines.elements();
while(e.hasMoreElements())
{
MyLine ln=(MyLine)e.nextElement();
ln.drawMe(g);
}
}
private void init() {
// TODO Auto-generated method stub
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
((Window)e.getSource()).dispose();
System.exit(0);
}
});
addMouseListener(new MouseAdapter(){
int orgX;
int orgY;
public void mousePressed(MouseEvent e)
{
orgX=e.getX();
orgY=e.getY();


}public void mouseReleased(MouseEvent e)
{
Graphics g=e.getComponent().getGraphics();
g.setColor(Color.red);
g.drawLine(orgX, orgY, getX(), getY());
vLines.add(new MyLine(orgX,orgY,e.getX(),e.getY()));
}
});
this.setSize(300,300);
setVisible(true);
}
}
这是一个画线重绘的小程序,在我机器上运行时,画得线并不是鼠标的两个点。
请大家帮着看看问题在哪?