当前位置: 代码迷 >> Java相关 >> repaint()方法
  详细解决方案

repaint()方法

热度:676   发布时间:2006-11-28 17:07:33.0
repaint()方法

刚我用了个repaint()方法,对它有点不解啊,只知道它是刷新的意思,我每次用它是不是会把画过的东西请空,再重画啊,真的很郁闷!!

搜索更多相关的解决方案: 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);
}
}
这个程序怎么实现不了我要的功能啊??


----------------解决方案--------------------------------------------------------
不好意思,我知道了,是我程序写错了
----------------解决方案--------------------------------------------------------