The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

I am having troubles understanding how to implement event handlers for my button "submit" or where to place the code. Can somebody give me some direction so that i might learn how to do this? I am struggling with it at the moment despite attempting multiple online tutorials and documentation. Much help is appreciated, please be gentle to the beginner!

EDIT: I have commented the specific code that i wish to have an event attached to.

Re: Help with event handling - beginner

I have read this already but failed to understand it. I figured the best way to learn how to implement handlers in practice is by seeing an example of my code with an event handler.

For example i do not know where or how to declare an event handler class, and whether or not that means actually creating a new class file to do so and then to reference it in my frame. Im clueless, yet it would help me in understanding this hugely if somebody could be so kind as to show this to me in practice in my own code.

Re: Help with event handling - beginner

You can do it a number of ways. Declare it as a separate class, or implement it using the same class, or instantiate an anonymous inner class. Try one, post what you've tried, and we'll go from there. The tutorial pretty much contains all the code you need.

I suppose the way it understands to link the event wıth that particular button is because the event happens in the addlistener bloc for the button, right? Why does that code end with this though "}); "? as opposed to just "}".