2

I'm trying to make a monopoly game in java, the thing is i'm very new to programming and this is my first program.

So without knowing about the dimensions of the frame, i made it too big because it was okay for my screen resolution, but when I try to use the game in another computer, it is so big that it doesn't even fit in the screen.

So my question is how can I make that my game can resize automatically so I can use it in another PC without affecting its dimensions?

Thank you very much :)

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373

4 Answers4

3

Assuming that you're creating a Swing application (you never say), the is to not size any of the components directly but rather to use an appropriate mix of layout managers, and let the layout managers and the preferredSize of your components do the sizing of the GUI for you. Always remember to add the components to the GUI, then call pack() on the top level Window, and then call setVisible(true) on the top level window.

For more details on just what layouts are available through core Java, please check out the tutorial, Laying out Components in a Container.

If your question does not involve the Swing GUI library, then please let us know which GUI library you're using. The question details are quite important, and you'll want to tell them to us from the start if possible.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • The thing is that if I do this, the board of the game just gets cut at half because it is too big for so small dimensions... so I don't know what to do :'( p.s yes, it is a swing application :) – Nicolás Múnera Oct 19 '12 at 03:48
  • @NicolásMúnera: then you've got to fix the bug. If you need our help in this, you'll have to give us enough information to be able to help you including code, preferably a *small*, compilable and runnable program, an [sscce](http://sscce.org). – Hovercraft Full Of Eels Oct 19 '12 at 03:53
  • *"cut at half because it is too big for so small dimensions"* Make the game squares smaller or drop it in a scroll-pane. Note that *"How can I resize my window in Java without affecting the dimensions?"* reads in my head as *"How can I have my cake, and eat it too?"*. – Andrew Thompson Oct 19 '12 at 05:37
1

If you're trying to make your game run in full screen, this may help: How can I get screen resolution in java?

Community
  • 1
  • 1
higuaro
  • 15,730
  • 4
  • 36
  • 43
1

Simulating such a game is not easy; you might want to start with something easier, such as MVCGame, which places components in a simple layout, or Buttons, which adapts the font size to the available space at a given level of difficulty.

For continuous scaling, you'll need to scale() the graphics context's transform to fill the drawing surface, as shown here. For rotated text, the examples shown here may be helpful.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

window.setExtendedState(JFrame.MAXIMIZED_BOTH); sets the window to full screen.

Mordechai
  • 15,437
  • 2
  • 41
  • 82