0

I designed a Swing application last week. It creates a JLayeredPane that contains a JPanel painted with a road map. On this JPanel, it is possible to create other JPanel that contain small points simulating cars.

I'm not sure that my code is perfectly written, but it works. However, I decided to create a JApplet from that Swing Application.

I replaced the "extends JFrame" with "extends JApplet" and wrote a init() method in it instead of the main method.

The problem is that the only panel that I can see on my JApplet is the map. On the Java Console, I can see that my JPanels are created, but they don't appear...

I don't want to use ten pages to show you the whole code, I hope that you will understand what I tried to explain. If you need some specific parts, I can give them to you.

T. Dex
  • 1
  • 1
  • 1- You should avoid extending from top level containers for this reason. Instead start by extending from something like JPanel. 2- It sounds weird to start using a JLayeredPane, but end up adding panels to the panel it contains. You should be adding all your panels to the layered pane – MadProgrammer Jul 02 '13 at 20:54
  • Sorry I was not clear enough. I have a JLayeredPane that contains a first JPanel with my map (level 0). At level 1, I have my JPanels with the moving cars, in my JLayeredPane. About your first comment, I should create a first JPanel, and not use a JLayeredPane or add my current JLayeredPane inside ? Actually, when I add my JLayeredPane in a JFrame, it works, my applet just opens a new window in my browser, that's why I don't get it.. – T. Dex Jul 02 '13 at 21:59
  • Basically, instead of putting your JLayeredPane on a custom frame, you should either, create a custom panel and place the layered pane on it or extend directly from the layered pane based on your needs – MadProgrammer Jul 02 '13 at 22:08
  • Alright, I'll try to create a class extending JLayeredPane that contains everything and my class extending JApplet will simply create a new instance of that JLayeredPane. Thank you for your time, I hope I understood well what you told me. – T. Dex Jul 02 '13 at 22:16
  • 1
    See also this [Q&A](http://stackoverflow.com/q/12449889/230513). – trashgod Jul 02 '13 at 23:41
  • Thank you trashgod, I wish I read this topic earlier... Finally, I made it as you said @MadProgrammer and it works, thank you. – T. Dex Jul 03 '13 at 14:19

0 Answers0