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();
}
}