开发者

Java: How can I load an external class into a gui

开发者 https://www.devze.com 2023-04-01 19:31 出处:网络
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 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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号