0

I have this statement:

private JButton button_array [] = {
    jButton1, jButton2, jButton3, 
    jButton4, jButton5, jButton6, 
    jButton7, jButton8, jButton9
};

This does not seem to work though and gives me an error of "illegal forward reference". How do I fix the statement?

1
  • 1
    You've got your array declared before the variables that it contains! Commented Feb 21, 2012 at 17:58

2 Answers 2

8

Your error is not related with your syntax. I guess your jButton1 and other buttons are declared after this statement. Take them upper part of your array declaration. Errors will disappear hopefully.

Legal:

private JButton jButton1, jButton2;
private JButton button_array [] = {jButton1, jButton2};

This one is illegal and gives "Illegal forward reference" error.

private JButton button_array [] = {jButton1, jButton2};
private JButton jButton1, jButton2;
Sign up to request clarification or add additional context in comments.

2 Comments

how would I get to compare my arrays? if (reset) { for (JButton button = button_array ) { button.setEnabled(true); button.setText(""); } turn = false; }
@mike157 if you have more of your code you'd like to add, please add it to the question statement using the 'edit' link underneath the tag boxes.
1
JButton[] jBtns= {new JButton("1"),new JButton("2")};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.