Using JButton to change used components in a JPanel with NetBeans
I'm using the NetBeans GUI designer to create a webpage using a Java applet. Right now, I have the basic GUI built and I have decided on creating a new class file for each 'page'.
So- The main screen has a JPanel for the menu and another JPanel for the main content window. Inside the main content JPanel, homePage.class is displayed. I would like to know if it is possible to use a JButton to change which .class file is displayed in the main JPanel (so instead of homePage.class being displayed, I would like to have about.class etc, etc)
Another question I have: Can you use links in the JApplet? I would like to use a JButton or JLabel to direct the web browser to other pages.
Thanks!
BTW- Here's an image (if it helps) of my current layout: http://timothyb89.homelinux.org/WebPageLayout.png
> I'm using the NetBeans GUI designer to create a
> webpage using a Java applet.
Maybe you shouldn't do that and give it a shot doing by hand, so you actually know what the designer does when you use it later. Another hint: don't even think about using appletviewer. That an applet runs on it means nothing at all.
> Right now, I have the
> basic GUI built and I have decided on creating a new
> class file for each 'page'.
Please, create classes instead, not files. Files are just a means to store classes.
> So- The main screen has a JPanel for the menu and
> another JPanel for the main content window. Inside
> the main content JPanel, homePage.class is displayed.
> I would like to know if it is possible to use a
> JButton to change which .class file is displayed in
> the main JPanel (so instead of homePage.class being
> displayed, I would like to have about.class etc,
> etc)
Please, really work on getting your terminology correct. You're not displaying any .class files. You might display instances of some component classes. You make it hard to understand you. If you now say "but I'm just a beginner", I'll say "then go back to the basics and don't even touch GUIs yet".
Look at the Swing tutorial http://java.sun.com/docs/books/tutorial/uiswing/ for CardLayout. You can use it for the "content" panel to display different panels. Changing the panels can of course be done by a click on a button.
But then, you might also want to consider using a JTabbedPane, because I feel that's what you actually want to have.
> Another question I have: Can you use links in the
> JApplet? I would like to use a JButton or JLabel to
> direct the web browser to other pages.
You can forward the browser to another URL using Applet's getContext(). This is not really "using links" though. It just has the same effect as clicking on one in an HTML page.
>Please, create classes instead, not files. Files are just a means to store classes.
Actually, it is correct- it is implying that I am using a separate file for each class.
Also, I had hoped that I would not have to use JTabbedPane, although I should just need a JLabel and set the text in it to get the same basic effect.
Also, thanks for the getContext()- I've been searching for ages on that and I finally know what it is now :)