用paint画图的疑惑 本帖最后由 lz12366 于 2009-10-07 21:36:25 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我发现 这样运行 总是出现 JFrame 的背景是后面桌面上的 图像如果把public void paint(Graphics g) { g.drawLine(x1, y1, x2, y2); x1 = x2; y1 = y2; } 去掉 则显示正常怎么回事呢??? 一般是用双缓冲去处理,如果不喜欢的话,用下面代码import java.awt.*;import java.awt.event.*;import javax.swing.*;public class TestTest extends JFrame{ /****/private static final long serialVersionUID = 1L;int x1, y1, x2, y2; public TestTest() { setVisible(true); setSize(300, 300); repaint(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { x1 = e.getX(); y1 = e.getY(); } }); addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { x2 = e.getX(); y2 = e.getY(); paint(); //repaint(); } }); } public void paint() { Graphics g=getGraphics(); g.drawLine(x1, y1, x2, y2); x1 = x2; y1 = y2; } public static void main(String args[]) { new TestTest(); }} jframe用 paint 可以实现有时常出现显示不正常 freemarker 关于TreeMap删除的问题~求教~ 移位问题 Applet 到底有没用 static初始化的问题 有谁用java开发过网管软件吗? 如果设置JList每行的分界线呀?(我想要看得到分界线)谢谢 请问哪个类可以实现“先进先出”? 怎么样让JTable随JFrame变大而变大 jar命令封包class的问题 启动qq怎么启动啊 ????? 关于Java中的Random类,熟悉的进
如果把
public void paint(Graphics g)
{ g.drawLine(x1, y1, x2, y2); x1 = x2; y1 = y2; }
去掉 则显示正常
怎么回事呢???
import java.awt.*;import java.awt.event.*;import javax.swing.*;public class TestTest extends JFrame
{ /**
*
*/
private static final long serialVersionUID = 1L;
int x1, y1, x2, y2; public TestTest()
{ setVisible(true); setSize(300, 300);
repaint(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);
}
}); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { x1 = e.getX(); y1 = e.getY();
}
}); addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { x2 = e.getX();
y2 = e.getY();
paint();
//repaint(); }
});
} public void paint()
{
Graphics g=getGraphics();
g.drawLine(x1, y1, x2, y2); x1 = x2; y1 = y2; }
public static void main(String args[]) { new TestTest();
}
}
有时常出现显示不正常