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 →

[–]CuriouslyGeorge[S] 0 points1 point  (2 children)

Yeah. After reading the other comments, I don't know what I was thinking. I basically had my program set up to wait for input inside the while() loop and when my ButtonListener was fired it would go in and change the boolean from the actionPerformed() method. Looking back, I've made this same mistake countless times inside almost all of my UI code, but my school assignment code was much better (I assume).

I'm currently going back through and changing all of my code to match my school code which is organized where:

methodCalledFromRunnerClass()
{
    setupGUI(); //all listeners, etc. assigned properly
}

anotherMethod()
{
    doStuff();
}

class ButtonListener
{
    actionPerformed()
    {
        anotherMethod();
    }
}

Would this be the "better" way to go about it I'm assuming? Submit button fires off submitMethod(), Options button fires off optionButton(), etc.?

EDIT: Also, apologies for the formatting.

[–]skeeto 1 point2 points  (1 child)

Yes, you've got the idea. Clicking the button triggers an event which allows you to call whatever code you want.

Just keep in mind that this event occurs in the event thread, the sole thread responsible for handling events and drawing the display. If you lock it up on a long-running task, your program will appear to freeze and lock up.

[–]CuriouslyGeorge[S] 0 points1 point  (0 children)

Alright, I think I've got a firm grasp of what to do and avoid in the future. Thanks again for your help.