Simple shape program will not draw
I have a very basic program, it creates a JFrame, then i have a separate class which creates a circle component i then add this to my JFrame. For some reason it won't draw the circle, it complies with no errors. I have added a fill colour to make sure i couldn't miss it.
EDIT: Ok, so i have got it to appear by placing frame.setVisible(true); below the frame.add() line. Could someone explain why it works this way but not how it is below?
JFrame, with component added
public class EmptyFrameViewer
public static void main(String args)
JFrame frame = new JFrame();
final int FRAME_HEIGHT = 800;
final int FRAME_WIDTH = 800;
CircleComponent circle = new CircleComponent();
public class CircleComponent extends JComponent
public void paintComponent(Graphics g)
Graphics2D g2 = (Graphics2D) g;
Ellipse2D.Double circle = new Ellipse2D.Double(0, 0, 400, 400);
Re: Simple shape program will not draw
You can't just add components to a visible window. You have to tell it to revalidate the layout if you do that, otherwise stuff won't show up properly. You should usually add all your components before making the window visible, but if you really need to add something after showing it, call revalidate afterwards.