Post #26 has over 26 if/else if and assignment statements.
You can replace ALL of them with the one statement in post #29
However you have to load the HashMap so its not that much less code.
...
Type: Posts; User: Norm
Post #26 has over 26 if/else if and assignment statements.
You can replace ALL of them with the one statement in post #29
However you have to load the HashMap so its not that much less code.
...
Give HashMaps a key and they return a value associated with that key.
...
} else if(key.equals("3")) {
JButton b = mainButtonList.get(8);
...
vs
With repeating code like you have, there must be a way to put all that in an array or a HashMap.
Before when?
Are you looking at my post #22?
Here's another version:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
@SuppressWarnings("serial")
Ok. There were no comments in the code, so all I could do was have the key press go to the action listener. I didn't know what to do then. The listener needs to recognize how it was called (button...
How is it supposed to work? What key presses are supposed to do what?
Here's my version that will react when the 'a' key is pressed.
import javax.swing.*;
import java.awt.*;
import...
If you use key bindings you may be able to bind the key events to the container that all the components are in.
The key binding's actionPerformed method could call the actionPerformed method used...
I thought that player1 was the only one. The add(player1); line should be commented out as are the ones underneath it.
The "this" refers to the JPanel that the code is in.
Sorry, there are so many ways for a program to "not work" that I have no idea what the problem is.
Sorry, I meant to say: Replace "player1" with a component in your code that is being displayed.
What I posted was for a quick and easy demo. I was hoping that you could copy and paste it as is.
Then test it by executing your code and pressing Ctrl-Z or the Y and have a message printed.
Did...
I don't see what bearing the use of ArrayLists to hold references makes to whether you use key listeners vs key binding.
I guess repetative code would have been a better way to say it.
Here's a...
A suggestion on your code. When I see regular code like you have I think array. Put the text for the buttons in an array in the order you want to index them:
String[] btnTexts = new String[] {"7",...