Created
August 18, 2011 02:55
-
-
Save brycethomas/1153193 to your computer and use it in GitHub Desktop.
Creating a 2-dimensional array of JButtons and setting the text on them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// an array of JButtons | |
JButton[][] buttons = new JButton[4][4]; | |
/* actually creates each of the sixteen JButton objects and sets | |
each button's text to look something like "Button [1][2]" (depending on row and column) */ | |
for (int i=0; i < buttons.length; i++) { | |
for (int j=0; j < buttons[i].length; j++) { | |
buttons[i][j] = new JButton("Button [" + i + "][" + j + "]"); | |
} | |
} | |
// set the text later on some specific button if we want | |
buttons[2][3].setText("changed text"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment