import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TestMouseLine extends JFrame
{
int x,y;
int endX,endY;
public TestMouseLine()
{
Container c=getContentPane();
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
x=e.getX();
y=e.getY();
}
});
addMouseMotionListener(new MouseMotionAdapter()
{
public void mouseDragged(MouseEvent e)
{
endX = e.getX();
endY = e.getY();
repaint();
}
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setSize(400,300);
setLocation(400,300);
show();
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.red);
g.drawLine(x,y,endX,endY);
}
public static void main(String[] args)
{
new TestMouseLine();
}
}
super.paint(g);这句话是什么意思呢?为什么加了这句话就只能画一条线呢?如果要用鼠标控制画更多的线应该怎么弄呢?