一个用jbuilder画图的问题
在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图像和所画线重叠的情况。
不知错在何处?