private JButton b1=null, b2=null, b3=null, b4=null, b5=null, b6=null, b7=null, b8=null, b9=null;
No need for this. Declaring and initializing an array of length n is equivalent to declaring n references to that type.
So these two lines:
JButton[] xx; xx = new JButton[9];
create the references you need for your buttons.
Now since you never initialize b1 through b9,
xx[0] = b1; ... xx[8] = b9;
doesn't actually do anything. The array's contents were null before and they remain null after.
You can get rid of that part, in fact you can get rid of b1 through b9. The loop is what does the work, and it looks to me like you got that part right.
Small matter of style: I prefer to do my imports individually, rather than using the wildcard. It doesn't make a difference, since java only loads the ones it needs, but it serves as a good heads-up to someone reading your code, if they know ahead of time what libraries they're going to see. This is not very important, what you should take away from it is that everything in your code should be aimed at communicating your intent to the person reading it. Any code that you write after school will be either useful or not. If it's useful, it will be maintained, modified, and extended by people other than you. I presume you want to write useful code, therefore you should get in the habit of writing code that speaks to the maintainer.
This is actually much more important than comments - comments in the real world are only used sparingly, when something is not obvious in the code.

New Topic/Question
Reply




MultiQuote





|