0

I am making a game and need a hell of alot of varibles. it is all so GUI so I need alot of Jbuttons. can I do it like something what I have below???

char[] mine=new char[3];
for(int count=0;count<10;count++){
//String add = "one"+count;
JButton mine[count] = new JButton("");
}

heres the error

C:\Documents and Settings\Adam\Desktop\work\MineSweep.java:42: mine is already defined in MineSweep()
final JButton mine[count] = new JButton("");

Edited by Nick Evan: Fixed formatting

3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by server_crash
0

You've defined "mine" twice.

char[] mine
JButton mine

which is it?

int count = 10
JButton[] guiButtons = JButton[count];
 
for(int i=0; i<count;i++)
{
	guiButtons[i] = new JButton();
}
0

First of all, that wont work..Plus the array would be indexed out of bounds if it did. What are you trying to do with the chars? If I knew, I could give you some better code:

JButton[] myButtons = new JButton[10];
char mine = '*';

for (int i=0; i<myButtons.length; i++)
{
       myButtons[i] = new JButton(" ");
       myButtons[i].addActionListener(this);
}

public void actionPerformed(ActionEvent ae)
{ 
              //choose three buttons you want as bombs
              if (ae.getSource() == myButtons[0])
             {
                     myButtons[0].setText(mine + "");
             }
             else if (ae.getSource() == myButtons[1])
             {
                      myButtons[1].setText(mine + "");
             }
              else if (ae.getSource() == myButtons[2])
              {
                      myButtons[2].setText(mine + "");
              }
}

I guess that's something like what your wanting...If it's not, give me some more information, and I can help some more.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.