• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding components to JFrame  RSS feed

 
p haccius
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I'm using 1.5, so according to my course materials I don't need to create a Container in my class, or use getContentPane().

OK, but my book skims over what you do instead! I have a class that extends JFrame, with 3 panels full of stuff in there. After adding all the stuff, I go:

add(displayPanel,BorderLayout.NORTH);
add(keyPadPanel, BorderLayout.CENTER);
add(functionPanel, BorderLayout.EAST);

but all 3 of these lines crash in the compiler, with
invalid method declaration; return type required.

What declaration? I'm just calling "add" without doing this part:

Container cp = getContentPane();
cp.add(displayPanel,BorderLayout.NORTH);

[Mind you, it didn't like "cp.add" either! What is it complaining about?]

Thanks to anyone who can help ...
P
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

It looks like those 3 lines are in the body of your class and not inside a method (or constructor), which is where they need to be.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!