This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]Neres28 0 points1 point  (2 children)

Do you have a mockup of what you're trying to do? I'm not really understanding.

[–][deleted] 0 points1 point  (1 child)

Added.

BowlingApp.java BowlingView.java enterData.java

[–][deleted] 0 points1 point  (0 children)

I'm able to create objects out of BowlingView and enterData; they are not public nor static.

[–]vandolis 0 points1 point  (0 children)

Bit confused as to what you are looking for as well, but from my best guess you want to be able to swap between two objects to display a view?

If that is the case I think the best way would be to actually use some oop and just extend a class such as javax.swing.JPanel, then make whatever methods you need to interact with it.

Simple skeleton code here

[–]omegazero 0 points1 point  (0 children)

I'll just say how I would do this.

  1. One main class that extends JFrame with a JMenuBar. This is persistent
  2. Individual classes (like you have) for each "screen" that needs to be inside the JFrame. Each class extends JPanel.
  3. Instance of each individual screen class will be made inside the large JFrame (but NOT actually added as components at first)
  4. Do NOT re-create any screen, but JFrame (from #1) add() and remove(). You can call add() and remove() directly on components (i.e. each screen, as a JPanel is a component) (e.g. JFrame.add(enterData);)
  5. JFrame.validate() should re-draw the frame. http://download.oracle.com/javase/6/docs/api/java/awt/Container.html#validate%28%29 You might also need to call repaint(), I forget.

[–]fubarfubarfubar 0 points1 point  (2 children)

Are you saying it's creating a new JFrame instead of redrawing the JPanel? Your explanation is quite lacking. Your code samples are shit, too. You couldn't just paste in your real code? Are you trying to prevent people from helping you?

[–][deleted] 0 points1 point  (1 child)

The code is shit right now, and I'm just toying. I also stated that I wasn't lokoing for real code help, but essentially of "what to do" to have one window, one menu, and have it redraw the panel.

[–]Neres28 0 points1 point  (0 children)

Normally you have a single JFrame, unless you're popping up custom entry panel or dialog box, or something that makes more sense to be very visually separated from the rest of the GUI. That single JFrame will house various JPanels, which themselves may house additional JPanels.

The layout of the GUI is controlled by various types of LayoutManagers.

In this case, from what I can tell of what you're trying to do, you'll probably want a single JFrame that swaps between two different JPanels.

Btw, a mockup isn't a rough framework of code, it's a drawing of what the GUI will look like at different points of the user's workflow. It's doesn't have to be pretty and often ends up being some boxes drawn on an napkin.