G
glennsnoise
Hi. I'm designing a Wheel-of-Fortune kind of layout using JButtons
with ActionListeners to guess letters for words (kind of like Hangman,
but using JButtons). I've set up a for loop that gives me 26 JButtons,
but right now, all 26 buttons display "A". Can anyone tell me how to
add an increment function to this so that each button will display a
different letter of the alphabet?
Here is what I have so far:
import javax.swing.*;
import java.awt.*;
public class GhostGUITwo extends JFrame {
public static void main(String args[]) {
new GhostGUITwo();
}
//FRAME
public GhostGUITwo() {
this.setSize(800,600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Ghost");
this.setLocationRelativeTo(null);
GhostGUITwoPanel panel = new GhostGUITwoPanel();
this.getContentPane().add(panel);
this.setVisible(true);
}
//PANEL
public class GhostGUITwoPanel extends JPanel {
public GhostGUITwoPanel() {
for (int i = 0; i < 26; i++)
this.add(new JButton("A"));
}
}
//add JLabel and ActionListener
//JButton ClickMe adds corresponding letter to JLabel
}
with ActionListeners to guess letters for words (kind of like Hangman,
but using JButtons). I've set up a for loop that gives me 26 JButtons,
but right now, all 26 buttons display "A". Can anyone tell me how to
add an increment function to this so that each button will display a
different letter of the alphabet?
Here is what I have so far:
import javax.swing.*;
import java.awt.*;
public class GhostGUITwo extends JFrame {
public static void main(String args[]) {
new GhostGUITwo();
}
//FRAME
public GhostGUITwo() {
this.setSize(800,600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Ghost");
this.setLocationRelativeTo(null);
GhostGUITwoPanel panel = new GhostGUITwoPanel();
this.getContentPane().add(panel);
this.setVisible(true);
}
//PANEL
public class GhostGUITwoPanel extends JPanel {
public GhostGUITwoPanel() {
for (int i = 0; i < 26; i++)
this.add(new JButton("A"));
}
}
//add JLabel and ActionListener
//JButton ClickMe adds corresponding letter to JLabel
}