Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Java GUI Minesweeper Grid(Java GUI)
Java GUI Minesweeper Grid [message #1234153] Tue, 21 January 2014 11:01 Go to next message
Soerili R is currently offline Soerili RFriend
Messages: 3
Registered: January 2014
Junior Member
Hey guys,
I want to programm a Minesweeper game and I already have a grid or this.
When a button from this grid is pressed, he should change, but i don't know how to "activate" the buttons. At the moment you can press them and nothing happens.
Can it be done with ActionEvent? And how?
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Minesweeper extends JPanel {
	public static void main(String[] args) {
		Minesweeper m = new Minesweeper();
		JFrame frame = new JFrame("My Minesweeper");
		frame.add(m);
		frame.setSize(400, 400);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

	JButton Felder[][];

	public Minesweeper() {
		this.setSize(400, 400);
		this.setLayout(new GridLayout(10, 10));
		Felder = new JButton[10][100];
		buildButtons();
	}

	private void buildButtons() {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				Felder[i][j] = new JButton();
				Felder[i][j].setSize(400, 400);
				this.add(Felder[i][j]);
			}
		}
	}
}


Thanks for your help in advantage,
Soerili

My english is probably not be the best :/

[Updated on: Tue, 21 January 2014 12:11]

Report message to a moderator

Re: Java GUI Minesweeper Grid [message #1234749 is a reply to message #1234153] Wed, 22 January 2014 18:13 Go to previous message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
These forums are for discussing topics related to Eclipse, not general Java programming questions. I suggest you try StackOverflow for those types of questions.

[Updated on: Wed, 22 January 2014 18:14]

Report message to a moderator

Previous Topic:Where is the NEW in Project?
Next Topic:Need Help Starting javafx
Goto Forum:
  


Current Time: Fri Apr 26 19:45:44 GMT 2024

Powered by FUDForum. Page generated in 0.08676 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top