Hi, i already have a Pacman game who shows the output (positions of the pacman and the ghosts, score, round) in cmd, but now i have to show that in a gui, and use the keyboard to move the pacman instead of giving the final position at the begining. The logic of the ghosts, the score, etc. its done. But now i have doubts about how to show the info in a window, a gridLayout and a vector of images will be ok?
I can ask the positions of every character and the food on the map its in a vector.
Forget about vectors (nobody uses Vector any more anyway) and grid layout or any other programming terms. Start by drawing what you would like to appear on screen. You can consider how to implement it later.
I would consider bypassing the GridLayout and instead provide a JPanel that you draw on by overriding the paintComponent(Graphics g) method. You could start off simply, by drawing colored circles (for example) to represent the various game items. Later you could replace the circles with small images. It's easy enough to calculate the grid placement for the various pieces. You'd have to hook this into your existing code to be able to query the row/column where pieces are to be drawn.
IMO, for the OP the GridLayout with multiple JPanels might be better than overriding paintComponent. The panels can be referred to via index (2,5) which would closely match the existing "positions"
The game items can be JLabel with the image. Since a JComponent can be added only once to the parent container, it would be very easy to "move" the item.
But i wanna know how to update the content that will be in each panel (JLabel) with a method. I have a "dataMap" where -1 is a wall, 10 is a regular pellet, 50 a power pellet, 0 a blank, and i can ask the position of pacman and ghosts with getters.
I've thought that in the Controller side i will modify the map and read it from the view side.
I already finished the game, or at least the playing board. Now i want to start it from a Menu JFrame, but when i do it, the game doesnt repaint and doesnt listen to the keyboard, its like the board is not getting focus.
In prompt its working OK, repainting, listening the keyboard...
But when i try with a menu, just repaint when the game ends (pacman die)...