2
这是我的简单代码。我真的不知道如何在JPanel
上添加绘制的椭圆。我之前做过一些绘画,但我从未使用过构造函数,因此我没有任何想法。向JPanel添加椭圆形状
public class Buffer extends JPanel{
public JFrame frame;
public JPanel panel;
public Buffer(){
frame=new JFrame();
panel=new JPanel();
panel.setSize(500,500);
panel.setBackground(Color.red);
frame.setSize(500,500);
frame.setVisible(true);
frame.add(panel);
}
public void paintComponent(Graphics g){
super.paintComponents(g);
g.fillOval(20,20,20,20);
}
public static void main(String args[]){
new Buffer();
}
}