GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Separating  the  Fraim from Menu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Separating  the  Fraim from Menu" Watch "Separating  the  Fraim from Menu" New topic
Author

Separating the Fraim from Menu

Michail Petrov
Ranch Hand

Joined: Sep 04, 2008
Posts: 32
Hi i create two file one contains the JMenuBar and the components and the second contains the JFrame





and the second






but when i compile it gives me error
what is the problem

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Michail Petrov wrote:... when i compile it gives me error
what is the problem


Can you tell us what error you are getting? Once we know what error then we should have a better idea of how to fix it. Copy and paste the error that you see so we get all the information (the exact name and location of the error).


Steve
Michail Petrov
Ranch Hand

Joined: Sep 04, 2008
Posts: 32
O the error is simple

it is " cannot find simbol method add(classes.firmFrame) "

it is in the second file hire frame.add(ff);
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

I see. Look at the API for javax.swing.JFrame. The add(...) methods expect Components. Your firmFrame is not a Component or a subclass of Component so it can't be added to the Frame. What you need to do is expose the JMenuBar from the firmFrame class so the mainFraim class has access to it. For example store the JMenuBar as a member variable, then provide a 'JMenuBar getMenuBar()' method which returns it.

Also, since you want to add a JMenuBar to the JFrame, I would suggest you not use JFrame#add(), but instead use JFrame#setJMenuBar().
Michail Petrov
Ranch Hand

Joined: Sep 04, 2008
Posts: 32
coud you give me simple code i can geht it i use the setJMenuBar but the result is the same
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Michail Petrov wrote:coud you give me simple code i can geht it i use the setJMenuBar but the result is the same


Well, I will give you some stock sample code so you can apply it to your application. Let's say I have a Name object that makes a firstName and a lastName. I then have a Person class that wants to print the firstName. The first thing to do would be to make the Name object. If Name looked the way firmFrame does in your application, then it might look like this:


And Person might try to do this:

If the goal is for Person to print Name's first name, well it won't work. I have to change Name so that the firstName becomes visible to Person. First I have to make a member variable in Name to store the firstName, then I have to make a method which returns that value.


Now Person can call Name's getFirstName() method in order to print it out:


Just to round things off, I will modify Name one more time, so that lastName gets the same treatment as firstName, just in case I want to print out lastName at some point as well:


Hopefully you will be able to see what you need to do and apply it to your application.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Separating the Fraim from Menu