Search:

Type: Posts; User: Norm

Search: Search took 0.12 seconds.

  1. Re: Trying to loop actionListeners together for 56 JButton objects to reduce code size

    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
  2. Re: Trying to loop actionListeners together for 56 JButton objects to reduce code size

    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.
  3. Re: Trying to loop actionListeners together for 56 JButton objects to reduce code size

    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...
  4. Re: Trying to loop actionListeners together for 56 JButton objects to reduce code size

    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?
  5. Re: Trying to loop actionListeners together for 56 JButton objects to reduce code size

    Have you fixed that problem? What happens now?
  6. Re: Trying to loop actionListeners together for 56 JButton objects to reduce code size

    That error is from a different cause. What variable has a null value when the code on line 104 is executed?
  7. Re: Trying to loop actionListeners together for 56 JButton objects to reduce code size

    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...
  8. Re: Trying to loop actionListeners together for 56 JButton objects to reduce code size

    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 =...
  9. Re: Trying to loop actionListeners together for 56 JButton objects to reduce code size

    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...
Results 1 to 9 of 9