wood burning stoves
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ActionListener illegal start of expression" Watch "ActionListener illegal start of expression" New topic

ActionListener illegal start of expression

Jerry Goldsmith
Ranch Hand

Joined: Nov 29, 2006
Posts: 53

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();

JOptionPane new_pane = new JOptionPane(new_panel);

JDialog new_dialog = new_pane.createDialog(parentFrame, "Test dialog");

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

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

I agree. Here's the link: http://aspose.com/file-tools
subject: ActionListener illegal start of expression
It's not a secret anymore!