Java: How can I load an external class into a gui
I'm looking for a specific functionality. I want to load a class that extends JPanel
for instance and show that JPanel
on a separate GUI class.
I'm looking for the ability to switch several of these classes out at will. I have an idea for an educational game software and the classes would be the different games.
I do realize that I can instantiate an instance of each class in my GUI class, but I ran into the issue of them not displaying properly when I try to switch between them. repaint()
only works on the last class I added to my开发者_StackOverflow社区 content pane. Not sure why as the multiple classes I instantiate are present, it just seems to ignore the preceding classes.
How to swap components?
You can either use CardLayout to switch all the component or add/remove them calling
container.revalidate();
container.repaint();
精彩评论