【发布时间】:2013-01-23 11:02:43
【问题描述】:
我使用paintComponent 方法在我的面板上绘制形状。但是,每次我最小化框架或调整它的大小时,它们都会消失。不确定要在我的代码中添加什么。
public class ShapePanel extends JPanel implements ActionListener, MouseListener{
int a,b,c,d;
Graphics2D g2D;
private Rectangle2D rect = new Rectangle2D(a,b,c-a,d-b);
public ShapePanel(){
addMouseListener(this);
setLayout(new GridLayout());
}
public void paintComponent(Graphics g) {
g2D = (Graphics2D) g;
g2D.draw(rect);
repaint();
}
//get methods for coordinates: MousePressed, MouseReleased
【问题讨论】:
标签: java swing graphics paintcomponent shapes