Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Global variables and for loops

815854Nov 17 2010 — edited Nov 17 2010
Hi,

I'm working on my project for my programming class (a Connect 4 game), and am now down to the gritty step of rewriting the whole code to make it look mildly professional. The original was this... disaster: http://zephyr.pastebin.com/7kfyaMRY -- yes, I know that will probably make any of you cringe. I'm trying to avoid the massive string of JPanel panelXxY = new JButton(""); by using for loops. I need to keep the variables global so that I can call them in my actionPerformed method, but apparently you can't put a for loop outside a method or main, and even if you could, apparently any variables declared in said for loop wouldn't exist outside that loop. So, any suggestions? Keep in mind that I've only even known what a String is for about... 10 weeks, so please nothing too complicated.

Thanks~
This post has been answered by doremifasollatido on Nov 17 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 15 2010
Added on Nov 17 2010
4 comments
598 views