0

How would I make an In-game window?

So to put this simply, I'm making a game. the window for the game is not full screen, it is only 1000 by 800 pixels. for this game, i am making a blueprint class for in-game windows, so that i can have a window for inventories, stores, main menu, pretty much anything you can think of. So, I've tried using JDialogs, but they are separate windows, and I kind of want it to be painted to the main panel... kind of like a JLabel, but as a window. I've been doing a lot of google searches, and tried a lot of different things, such as the aforementioned dialog, and label, but I'm just not sure how to do this. All I need is an in-game window/menu. does anyone know how to do this? Thanks in advance!

Additinal info: if anyone has played Guild Wars 2, or World of Warcraft, you know what i'm talking about. Think about the separate inventory windows, and store windows, etc.

EDIT: I tried what the comments suggested, and here's how I initialized the new panel:

setSize(w, h);
setLayout(null);
setBackground(new Color(0, 0, 0, 0));

And I add this panel using mainFrame.add(new GameMenu()); and nothing happens. When I make the frame, in the main method, I do it this way:

f = new Frame();
core.setFrame(f);
f.add(new GameMenu());
f.add(new Panel()); //panel is the main game panel
f.setVisible(true);

And it shows up and works just fine. So what is different about this, and why is my first way not working and the second work?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
PulsePanda
  • 1,806
  • 10
  • 33
  • 56
  • just add another `jpanel` – 0x6C38 Jun 10 '13 at 23:12
  • interesting idea, but how would i make the panel disappear behind the borders of the frame, not obviously take up the whole frame...? – PulsePanda Jun 10 '13 at 23:14
  • what do you mean *disappear behind the borders of the frame*? panels must be added to `jFrames` in order to be displayed and they are limited to the `jFrame` size, but they don't have to be the same size as the frame, it can be set using `setSize()` (altho I don't recommend you do so as it should be handled by using [Layout Managers](http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html)). – 0x6C38 Jun 10 '13 at 23:23
  • ahh alright ill try that and see how it goes – PulsePanda Jun 10 '13 at 23:29
  • If you want different panels to stack up, just use the [cards layout](http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html) – 0x6C38 Jun 10 '13 at 23:30
  • Perhaps you are after a `JDesktopPane` with `JInternalFrame` instances to hold the panels. E.G. as seen in [this answer](http://stackoverflow.com/a/9365450/418556). – Andrew Thompson Jun 11 '13 at 00:10
  • `Frame` has it's own layout manager (`BorderLayout`), which means only one component can occupy a given position (like `CENTER`). – MadProgrammer Jun 11 '13 at 00:14

2 Answers2

0

JInternalFrame might be what you are looking for. An internal frame is normally added to a JDesktopPane but it also works if you don't want that overhead. The Java Tutorial has a good introduction.

Tilo
  • 3,255
  • 26
  • 31
0

Figured it out! all i had to do was just make a smaller JPanel (cause i didnt know that you could make it do that XD) and have it do what i want! Thanks for the help though

PulsePanda
  • 1,806
  • 10
  • 33
  • 56