This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
In the actionPerformed(ActionEvent event) method in the class InputPanel, the first line of code is a decision statement determining if the event.getSource is a JButton. If the source is NOT a JButton, what else would it be?
Here is the class the question is referring to:
I believe it will be setSales. Is this correct? Thank you for any help given!
When I got as far as line 7, the answer was no. Even without reading the rest of it.
The source could in theory be anything. I am pretty sure that text components (including text fields) can fire action events if you push the enter key when they have focus, so that is one possibility. The instanceof operator is used to test whether the following cast is safe. So you now have three non‑object‑oriented features for the price of one:-
Making a GUI component a listener, unless it is listening for events originating in itself.
Use of instanceof.
You only have one source for the events, so add the listener to that source. Create a class which handles that event. Not the panel class.
Lots more in that code:-
You have almost certainly got too many fields in that class. A lot of those fields should be local variables.
Why are you returning an array of text fields from your method?
Why are you using ints rather than creating a Salesman class and having Salespeople arrays?
Why are you using "north", etc., for the Border Layout rather than the constants defined in the Border Layout class?
I shall move this discussion to our GUI forum because there is so much GUI‑related stuff to the question.