• Post Reply Bookmark Topic Watch Topic
  • New Topic

Actionperform not working

 
Prasad prap
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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());
}

}


}
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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:

 
Milan Agrawal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!