刚我用了个repaint()方法,对它有点不解啊,只知道它是刷新的意思,我每次用它是不是会把画过的东西请空,再重画啊,真的很郁闷!!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class J_Draw extends JFrame
{
int x1=0,x2=0,y1=0,y2=0;
int m_oldX=0,m_oldY=0;
public J_Draw()
{
super("Example of mouse event handling");
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
x1=e.getX();
y1=e.getY();
repaint();
}
}
);
addMouseMotionListener(new MouseMotionAdapter()
{
public void mouseReleased(MouseEvent e)
{
x2=e.getX();
y2=e.getY();
repaint();
}
});
setSize(400,400);
setVisible(true);
}
public void paint(Graphics g)
{
g.drawRect(x1,y1,x2,y2);
}
public static void main(String args[])
{
JFrame app=new J_Draw();
Container cp=app.getContentPane();
app.setBackground(Color.white);
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
这个程序怎么实现不了我要的功能啊??