I want to make something similar to a phone:
i want to have a display, and 10 buttons: 0-9 and enter button.
each time a press a button i want to display it on the screen(a TextField).
I`m thinking doing something like:
but i cannot apply switch to a Button array, i need to apply it to an int...any ideas?
I dont think you need to create an button array at all.
With the ActionEvent object you get on every single click event, you can call the getSource() method to identify which button object was exactly clicked and get the label out of that button.
There are so many things I could say about that code that I don't know where to start. For one, you've already discovered that you can't switch on a Button array. You can't switch on an int array either, so this shows you might need to go through a tutorial or two.
http://download.oracle.com/javase/tutorial/java/nutsandbolts/switch.html Note that the tutorial has already been updated to include switching on a String, which is a new feature of Java 7 and doesn't exist in Java 6.
That is nothing like object-oriented programming. Create a Listener class, which you have already tried, which takes the details from the button for its field
Also, you can even simplify your ActionListener implementation..Something like....
Checking the action command for every single button in a if-elseif-else might look a bit redundant to people.
This is the basic idea(and note - I have not tested the above code...).
I`m looking to implement a listener for the Enter button, when someone enters they're four digit ID, to do a search in a text file and retrieve the customers first name, second name and the account. I've tought of something but i''ll work on it later and let you know.
Thank again for all the help.
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)