In applet we are using init() method so inside of the init() method can we use the actionPerformed method or can't?.If we couldn't which place can be implements that action performend method.

Also you just give me the syntax for creating the actionperformed method in applet.And that applet must have implements init() method


Advance Thanks...

Recommended Answers

All 2 Replies

You don't call the actionperformed. It is automatically called whenever you click a button.
You implement it normally in the same way you do when you use javax.swing. Your applet should implement the ActionListener interface, then you will declare the actionPerformed method and write code inside it. Then you will add to your buttons that ActionListener (namely the applet like you do with normal java GUI).

If you want to call the actionPerformed method explicitely meaning you want to call the code inside in some cases, I would suggest to either call directly the code you put inside the actionPerformed method, or trigger the button clicked yourself. The JButton class has a doClick method for that purpose

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.