When I run this code, I cant see the oval, I can only see a blank frame.
I know that I can use the paintComponent(Graphics g)
method, but I am curious
to know why my code wont work.
public class Check {
public static void main(String[] args) {
Check c = new Check();
c.init();
}
public void init() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(3);
JPanel panel = new JPanel();
frame.setSize(new Dimension(800, 600));
frame.setTitle("Test");
frame.setVisible(true);
frame.getContentPane().add(panel);
Graphics2D g = (Graphics2D)panel.getGraphics();
g.setColor(Color.BLUE);
g.fillOval(50, 50, 50, 50);
}