1

I'm a beginner in Java. My code:

public PlanetSimulator() throws InterruptedException {
    JPanel panel = new JPanel();
    panel.setBounds(64, 35, 840, 600);
    Draw view = new Draw();
    panel.add(view);

Drawing in panel Sun and Stars and Black Background.

How can I say Java "Hey you see that panel? Draw there another thing" But I'm saying in to Java not from the PlanetSimulator, but main function.

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                PlanetSimulator frame = new PlanetSimulator();
                frame.setVisible(true);
                //DrawPlanetOne DrawPlanetOne = new DrawPlanetOne()
                //PlanetSimulator.panel.add(DrawPlanetOne)
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

But it doesn't work. Yes I known that I'm amateur. Rysowanie / Draw class http://pastebin.com/RkcTBxrN

VereX
  • 49
  • 7
  • Can you elaborate a bit on what your Draw.java does because i don't see you overriding paintComponent in your code. such as here - http://stackoverflow.com/questions/5446396/concerns-about-the-function-of-jpanel-paintcomponent . Also you need a JFrame for the window. JFrame contains a JPanel which you draw on. – CarefreeCrayon Aug 08 '15 at 14:28
  • Sry, http://pastebin.com/RkcTBxrN My Rysowanie (draw) class – VereX Aug 08 '15 at 14:44

1 Answers1

1

I assume, this will be a simulation. And if you like to simulate something with 30FPS, it will be hard with a Panel. You could use a library like processing to animate your planets and stuff. It's a lot easier as using a JPane. But you could call the repaint method?

Community
  • 1
  • 1
Kanteran
  • 80
  • 8