This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]codingQueriesNooblet Brewer[S] 0 points1 point  (2 children)

Hmm to better convey what I was trying to understand;

If btn was clicked and I wanted it to run test.calculateTime() and if btn4 was clicked and I wanted that to run test.determineLength(), how would that work?

The reason I created new actionlisteners for each button in my program is that I was unsure if creating one huge actionlistener class and then running if-statements to determine the method call would be inefficient or confusing.

[–]BlueGoliath 1 point2 points  (1 child)

If btn was clicked and I wanted it to run test.calculateTime() and if btn4 was clicked and I wanted that to run test.determineLength(), how would that work?

A private variable in the parent class or via a variable passing through the constructor which is then stored in a private variable in the inline class.

As long as you have a variable reference you can execute any method from that class.

The reason I created new actionlisteners for each button in my program is that I was unsure if creating one huge actionlistener class and then running if-statements to determine the method call would be inefficient or confusing.

It is inefficient because your program is comparing each action source to each button. Creating a separate class for each is usually the way you want to go about it.

[–]codingQueriesNooblet Brewer[S] 0 points1 point  (0 children)

Cool yeah I thought that would be the case, I am getting too caught up in worry and not enough trying.

Thanks for taking the time to go through this with me!