I need SERIOUS Java help RE: action listeners

Ok, I have been tearing my fucking hair out for the past three days trying to get a single fucking button respond to a generic event. It is the only button on the page.

I have seen so many different error messages that I can’t even begin to explain my frustration here.

I cannot seem to add a listener to the button because I have no clue where to put the class which acts as the interface. Is it the JFrame class which I create an instance of? Is it the class which adds all the stuff and creates the instance of the other class? Do I create an inner class in either of the two classes?

And, most importantly, since the actionPerformed method is declared void, and it must be inside an ActionEvent class, how the fuck do I reference any component at all?

I stare at my two teach yer’self Java books with a dumb face. I page over and over through my Java almanac, trying to even get a feel for how these fucking things need to associate.

I got nothing, and I am starting to literally pound my keyboard so I guess its time to call in some help if it is out there.

I don’t understand your point about which class acts as the interface. I assume you do not mean the technical meaning of interface.

ActionListeners are usually implemented as anonymous inner classes of the same component that contains the component they are listening to. For example, if you have a JFrame with a JButton you want to listen to with an action listener, you would instantiate your JButton, add it to the JFrame, and addListener(< anonymous inner class definition >).

Since it is an inner class defined in the JFrame, it should have access to all methods and variables that the JFrame does, that’s how you can access them.

I’ll look for some simple source code for you.

this page has some explanations of inner classes and example code.

Aww, I just got it.

What erl did right: almost nothing.
What erl did wrong: no constructor methods for subclassing in order to get an instance of a window with a damn interface in it.

sigh

Now, if I can just get it to display what I want it to before I clik the button I’ll be ok.

Thanks for the attempt. I should note the ironic sentence in the page you linked:

:stuck_out_tongue: