Campbell Ritchie wrote:Welcome to the Ranch
I tried adding code tags to your code, which makes it look better (), but your indentation is inconsistent and there were excess blank lines, which I deleted. Consistent indentation is a good way to see errors before they cause problems.
I suspect there is a design problem; if I see source == or anything I suspect you have been using addActionListener(this) whereas you should create a Listener for each button. Three buttons, three Listeners.
You should also not try to count clicks inside your method. You do not double‑click a button, so you don’t usually count clicks. And how is the click count ever going to be < 1?
I can see some problems about new Team(). You then calling its fields and setting the text from those fields. Those fields may be null, so surely you should be setting the fields from the text?
Never use == true or == false. I have explained why not here.
Campbell Ritchie wrote:I would recommend separate Listeners, yes.
I would also suggest you don’t count clicks.
And I would suggest you take the text from the text components and pass it to the Team constructor. You may need some validation of the text, however. That can be a very advanced topic.
I don’t understand how you need three buttons to get size, etc. You can use one button and one actionPerformed method to call several methods which find the size, etc. Presumably you have the size in a text component somewhere already?aal fak wrote: . . . My problem is that I need to get the size and other methods of the Team class when clicking the other two buttons.
Yes, somewhere in the Listener which you add to the create button, it will say team = new Team(...);I'm required to initiate the object of the team class in the first button's body, . . .
Don't get me started about those stupid light bulbs. |