• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with Class interactions

 
Michael Eller
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am just getting back into this and have a question that is giving me a problem.
I have a class that implements the JFrame (this class also contains the main function).
I have another class that provides the menubar, menus, etc to the class with the JFrame.
Everything works fine until I try to add an action listener to a menu item that will change something in the JFrame.....the two classes will not talk. I cannot use the
"class" <variable> = new "class" which would call the constructor....to implement this in this way would call the constructor for the JFrame class....and this is no good.
How can I access objects between classes without calling the constructor?
Any assistance is greatly appreciated,
Mike
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may create the menu from the Frame.
To make the menu able to modify things belonging to the frame, the menu needs a reference to the frame.
So the frame should hand this reference to the menu:
(Pseudocode
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic