• Post Reply Bookmark Topic Watch Topic
  • New Topic

'class' or interface expected error  RSS feed

 
Clare Wright
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,

Would appreciate some help on the code below. I thought this error was brought on by missing braces etc - the compiler doesn't seem to like the Panel center = new Panel(); line. By importing java.applet.Applet I thought it would work fine.

import java.awt.*;
import java.applet.Applet;

public class NestedPanels extends Applet {
public NestedPanels () {
Panel center = new Panel(); //error happening here
// error is: 'class' or 'interface' expected Panel panel = new Panel();

center.setLayout(new BorderLayout());
center.add("South", new Button("south"));
center.add("North", new Button("north"));
center.add("East", new Button("east"));
center.add("West", new Button("west"));
center.add("Center", new Button("center"));

Panel south = new Panel();
south.setLayout(new FlowLayout());
south.add(new Button("Help"));
choice = new Choice();
choice.addItem("one");
choice.addItem("two");
choice.addItem("three");
choice.addItem("four");
choice.addItem("five");
south.add(choice);
messageBar = new Label("This is a message bar.");
south.add(messageBar);

setLayout(new BorderLayout());
add("North", new Button("North"));
add("East", new Button("East"));
add("West", new Button("West"));
add("South", south);
add("Center", center);

}

protected Label messageBar;
protected Choice choice;
}


Thanks.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you make a Panel.java file ? Maybe it conflicts with the API's Panel class.
[ July 26, 2006: Message edited by: Satou kurinosuke ]
 
Clare Wright
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found the problem. Ingeniously I had another Panel.java file in the directory - bad move I have learnt from this mistake.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This answers my question
 
Clare Wright
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yip! You were exactly correct!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!