File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes ActionListener illegal start of expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ActionListener illegal start of expression" Watch "ActionListener illegal start of expression" New topic
Author

ActionListener illegal start of expression

Jerry Goldsmith
Ranch Hand

Joined: Nov 29, 2006
Posts: 53
Hello,

I'm attempting to use an action listener to read the contents of a text
field into a string when the enter key is pressed. I am getting an
"illegal start of expression" error on the line:
"public void actionPerformed(ActionEvent e)"
at compile time. I have included the code below.

What am I doing wrong? This is probably an obvious error to the Java pros out there; but, I am still fairly new at this. Thanks.

import javax.swing.*;
import java.io.*;
import java.awt.*;

public class Jerry_Test implements ActionListener
{

public static void start()
{

JFrame parentFrame = new JFrame();
JLabel new_label = new JLabel("New part number");
JTextField new_text = new JTextField(50);
JPanel new_panel = new JPanel();
new_label.setLabelFor(new_text);
new_panel.add(new_label);

JOptionPane new_pane = new JOptionPane(new_panel);
new_pane.setWantsInput(true);

JDialog new_dialog = new_pane.createDialog(parentFrame, "Test dialog");
new_dialog.setModal(false);
new_dialog.setVisible(true);
new_dialog.toFront();

new_text.addActionListener(ActionListener);
public void actionPerformed(ActionEvent e)
{
String new_name = new_text.getText();
});

}

public static void stop()
{
}

}
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Jerry Goldsmith
Ranch Hand

Joined: Nov 29, 2006
Posts: 53
Craig,

Thanks for the suggestion. It makes sense but when I try it I get a
';' expected error, on the line below
"new_text.addActionListener(ActionListener)", where I add the additional
"{".

This seems to jibe with the example code I've been looking at. I can't figure out what is wrong.
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
If you want to create an anonymous inner class implementing the ActionListener interface it should look something like

 
Consider Paul's rocket mass heater.
 
subject: ActionListener illegal start of expression
 
Similar Threads
getText() doesn't work
"...not abstract and does not override abstract method..."
Adding a text field to JDialog with JTextField
Why doesn't my WindowListener work?
OK button does not dispose of parent frame within ActionListener