Do all the JButton objects need to have their own unique variable names?
Create new JButton objects inside the loop just before setting their icons and assign them to the elements of oButtons
Type: Posts; User: Norm
Do all the JButton objects need to have their own unique variable names?
Create new JButton objects inside the loop just before setting their icons and assign them to the elements of oButtons
Check out the end of my last post.
Also remove the hardcoded value 56. Use the .length field of an array to control the looping.
This code has the repeated groups of very similar code. I thought that was going to be merged into a single method with an array and loop to handle instead of all this repeated code.
The problem...
Sorry, the small bits of code that have been posted probably don't show the problem.
Can you make a small, complete test program that compiles, executes and shows the problem?
Have you fixed that problem? What happens now?
That error is from a different cause. What variable has a null value when the code on line 104 is executed?
Are the image files in the correct location? You get a NPE when the image files are not found:
new ImageIcon(new TestCode24().getClass().getResource("NoFile"));
The above statement gives...
The value of m will have changed (actually lost when the loop exits) when that setIcon() method is called.
This might work:
for(int m=0; m<56; m++)
{
String tempName =...
Please copy the full text of the error message and paste it here. It has important info about the error.
When there is a bunch of repeated code, often it can be reduced to a method that is called...