Search code examples
javaswingappletframejapplet

Multiple jAppletForm in a Java applet


I've created a new Java project without main class in NetBeans and then I've added a jApplet Form (let's call it MainWindow.java) to my project package. After that, I've added few other jApplet Forms that represent different "pages" of my applet application to my package using the GUI builder of NetBeans.

When I run my applet, I can see the MainWindow form with some buttons, label, etc. on the AppletViewer just fine.

Now, I want to make an event when one of my buttons on my MainWindow is pressed, to show another jApplet Form that I've created earlier and show that form instead of the MainWindow form. I'm trying to create a simple navigation system in my jApplet, and I don't know how to make it efficiently!

Can anyone help me with the code that I should write in the MouseClicked event of my button to make it show another form?


Solution

  • Basically, you can't (or shouldn't) design applets like this. There is no effective means to switch from one applet to another.

    Instead, you should create one master applet and using something like CardLayout, design separate forms using one thing like JPanel

    You'd then able to switch the forms using the CardLayout manager as needed