• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Actionperform not working

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi people i am just new to Java programming especially to swing.I am just checking various things on java and running my programs on Eclipse.
I am checking few event handling stuff.I am getting error and my applet is not being initialised due to this.
Please tell me what could be the error.Following is the program:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;




public abstract class test extends JApplet implements ActionListener{

/**
*
*/
private static final long serialVersionUID = -2165717127504007034L;
public void init(){
JTextField jtf = new JTextField(15);
Container contentpane=getContentPane();
JButton jb=new JButton("France");
jb.setActionCommand("France");
jb.addActionListener(this);
contentpane.add(jb);
contentpane.add(jtf);

public void ActionPerformed(ActionEvent e) /* error shown here saying that Multiple markers at this line
- void is an invalid type for the variable ActionPerformed
- Syntax error on token ")", ; expected
- Syntax error on token "(", ; expected
*/

{
jtf.setText(e.getActionCommand());
}

}


}
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Please confirm that you have spelt the code correctly; the method is public void actionPerformed(java.awt.event.ActionEvent), not ActionPerformed.
 
Prasad prap
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No i did that also.But has the same problem.If i proceed but running the applet even with errors following errors are obtained in console part of eclipse at the bottom:

java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:798)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:727)
at sun.applet.AppletPanel.run(AppletPanel.java:380)
at java.lang.Thread.run(Thread.java:636)
load: test2.class can't be instantiated.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My best guess is you have the placement of the actionPerformed method inside another method. I say this because after

contentpane.add(jtf);

I don't see a closing } before you have the actionPerformed method. It would be something like this:

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that both of them are correct.

The spelling of actionPerformed() is wrong as well as it is defined inside init() function.
 
reply
    Bookmark Topic Watch Topic
  • New Topic