-1

I'm trying to make a building game (~Age Of Empire :). So, I want to write a program that divides a JFrame (containing the map of my game) to squares. Then allows every square of the frame to be modified (to contain an image). For example, I want to put an image in square (1,1), then add an image in square (4,2) and keep the image that I had in square (1,1).

How can this be done?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Fadil
  • 1
  • 1
  • So did you write any code? – hyades Apr 25 '15 at 08:39
  • I'd suggest reading up on [Layout Managers](https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html). GridLayout sounds right for what you're trying to do. – PakkuDon Apr 25 '15 at 08:40
  • @hyades Yes, I can play the game (even loose x) on the console. Its my first time creating a graphic interface, I wanted to know what tools are better suited for what I m trying to do. – Fadil Apr 25 '15 at 08:47
  • `JPanel`s and `GridLayout` – MadProgrammer Apr 25 '15 at 08:50
  • 1
    See also [Making a robust, resizable Swing Chess GUI](http://stackoverflow.com/q/21142686/418556). (It uses buttons, but you might also use a `JLabel` instead of each button.) – Andrew Thompson Apr 25 '15 at 08:55
  • 2
    For [example](http://stackoverflow.com/a/22423511/230513). – trashgod Apr 25 '15 at 08:57

1 Answers1

0

To do this inside the JFrame just use a GridLayout, create a control to match a square on the map (for now you could just use a JLabel or JButton) and add them to the screen.

I can't really recommend using Swing for developing a game though, you'd be better off looking into one of the many 2D (or 3D) for that matter game engines out there. They will allow you to get much more impressive results and do some of the work for you.

Tim B
  • 40,716
  • 16
  • 83
  • 128