我很困惑如何通过将jpanel作为参数来在其上绘制圆形。
public class test extends JPanel{
public test(JPanel jpanelcomponent) {
}
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
int width = getWidth()/2;
int height = getHeight()/2;
g.fillOval(5, 5, width, height);
}
}
Circle
类,该类具有自己的draw(Graphics)
或draw(Graphics2D)
方法。在主面板中保留它们的列表。在paintComponent(Graphics)
上,绘制形状实例即可。 - Andrew Thompson