Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JMenu layout, syntax error on variables  RSS feed

 
Matt Fielder
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to set up my main GUI as a JFrame. I have the main frame and want to add the JMenuBar with a few main options with some sub-options. I'm working in Eclipse and am trying to figure out Eclipse's error message.

When I put this:


I am getting the error:
Syntax error on token ";", { expected after this token

after the subMenuItem; declaration.
If I comment out the JMenuItem line, the error moves to the line above.
Does Eclipse think this is the beginning of a method? Did I do something wrong?

I'm working through this with this page:
http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html
as a guide. Pretty much the same declarations are used there.

Ideas?
Thanks in advance.
Matt
[ March 06, 2005: Message edited by: Matt Fielder ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the code on that page is intended to be inside a method; is that where you've put it? i.e.

 
Matt Fielder
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In another example, this GUI setup and layout was within the main class's constructor. Is this wrong?

I don't know if each section should be within its own class to keep each section at a minimum?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not wrong, no. I personally don't like to see that arrangement, but it's a style issue only.

Generally any time you're writing a method that's 50 lines long, you ought to be looking for ways to break it up. Sometimes that does indeed mean using multiple classes, but here it probably just means using several methods in a single class.

So did you solve your problem yet?
 
Matt Fielder
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So then maybe this...?

main class
constructor for JFrame (just construct a JFrame and initialize its generic states)
main method
calls to:
all individual elements to be added to JFrame called from seperate classes


and not keep the main JFrame together?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!