I'm trying to program the traditional minesweeper game. I have problems with Swing as I'm not sure how to proceed.

I tried adding one JPanel to a JFrame and then using JButtons to imitate the tile buttons. Then I encountered a problem when I tried to program the functionality of opening the tiles. I tried to replace the JButton with JLabel with no success.

Could you give me some opinions on how to start the gui programming? Algorithm are ok I think.

Recommended Answers

All 4 Replies

Perhaps JToggleButton will work for you. You can set separate images for icon, selected icon, disabled icon, etc.

So what is the requirement? A grid of jThings that can be clicked by the user and can display icons that change as the game progresses? Either JButton or JLabel will do that for you, although the JButton syntax is more natural for something that can be clicked but not typed into.
Perhaps you need to describe the problem you had in more detail, because the grid of JButtons definitely can work, and work easily.

So what is the requirement? A grid of jThings that can be clicked by the user and can display icons that change as the game progresses? Either JButton or JLabel will do that for you, although the JButton syntax is more natural for something that can be clicked but not typed into.
Perhaps you need to describe the problem you had in more detail, because the grid of JButtons definitely can work, and work easily.

Should I make also a grid of JPanels under the JButtons? When I use setVisible(false) on the JButtons they disappear but the grid shifts left and that is also a problem. JPanels could be solution.

No, just a grid of buttons. Don't make them invisible, just change their icons to a blank icon (or no icon/text at all).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.