This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Separating the Fraim from Menu

 
Michail Petrov
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Michail Petrov
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
coud you give me simple code i can geht it i use the setJMenuBar but the result is the same
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic