Question

So I have this project to make and I'm somehow stuck. I have an encyclopedia to make and I do not know how to make the pages. For example, I have a JFrame with two buttons, called Back and Next. When I press that button, I want my program to switch to the next page, same as an e-book. I thought of creating a new JPanel, get the X and the Y of the first frame and close the first frame when this one opens, reopen it only when I press back. How can I do that?

Was it helpful?

Solution

You have several options:

  • Create new JPanels for each "page" and swap them via a CardLayout.
  • Create a single JPanel for displaying page information, and then swap content on pressing the button. I favor this solution if at all possible as the simplest and the one best suited to a good MVC solution.

As an aside, if you're new to the Swing GUI library, then I suggest that you put the GUI-builder to the side for a bit til you learn the underpinnings of the library. This will help prevent you from painting yourself in a corner should you use the GUI builder later.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top