一个用jbuilder画图的问题

boyard 2004-06-11 03:27:29
在Frame1中的一个Button,用于打开一个绘图的新窗口DrawFrame,按钮代码如下:
void jButton1_mouseClicked(MouseEvent e) {
JFrame dFrame = new DrawFrame();
dFrame.setSize(new Dimension(600, 400));
dFrame.setTitle("绘图框");
dFrame.setLocation(100,100);
dFrame.show();
}
DrawFrame中的绘图类:
public class DrawPanel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponents(g);
Graphics2D g2 = (Graphics2D)g;
g2.setPaint(Color.black);
g2.draw(new Line2D.Double(40, 40, 40, 200));
}
}
程序运行后,在绘图框中,出现了Frame1图像和所画线重叠的情况。
不知错在何处?
...全文
64 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
boyard 2004-06-12
  • 打赏
  • 举报
回复
天哪,居然出了这种错。
谢了,stamp80(清风扑面)!
stamp80 2004-06-11
  • 打赏
  • 举报
回复
只是因为你写错了一个字母,应该是
super.paintComponent(g);
而不是super.paintComponents(g);
注意这个s。

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧