Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

<identifier> expected error received

807601Apr 28 2008 — edited Apr 28 2008
Hello,
As with others, I am pretty new to Java and I don't understand why I am receiving this error when I have working through the steps to set up this code from a textbook. I have recevied this error from JGrasp when compiling my program:
JGreet4.java:18: <identifier> expected
* viewButton.addActionListener(this);*
I also highlighted the line in the code it is referring to.

Any assistance in resolving this error. As I said, it is from a textbook and I am working through the steps...Thanks!

My code listing is below:

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

public class JGreet4 extends JApplet implements ActionListener
{
Container con = getContentPane();
JLabel greeting = new JLabel ("Greetings!");
Font bigFont = new Font("Times Roman", Font.ITALIC, 24);
JLabel firstLabel = new
JLabel("Please enter your first name:");
JLabel lastLabel = new
JLabel("Please enter your last name:");
JTextField firstField = new JTextField("",10);
JTextField lastField = new JTextField("",10);
JButton viewButton = new JButton("View Greeting");
*{color:#ff0000}viewButton.addActionListener(this);*
*{color}* FlowLayout flow = new FlowLayout();
public void init()
{
greeting.setFont(bigFont);
con.add(greeting);
con.setLayout(flow);
con.add(firstLabel);
con.add(firstField);
con.add(lastLabel);
con.add(lastField);
con.add(viewButton);
firstField.requestFocus();
}
public void actionPerformed(ActionEvent thisEvent)
{
String firstName = firstField.getText();
String lastName = lastField.getText();
greeting.setText("How are you, " + firstName + " " +
lastName + "?");
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 26 2008
Added on Apr 28 2008
7 comments
215 views