• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Separating the Fraim from Menu

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic