Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating JFrame from a child JFrame

Status
Not open for further replies.

agodfrey

Technical User
Jan 25, 2008
2
US
Hi, I am writing a Java program that uses a menu that is set up as a JFrame and one of the panels in it contain a ImageIcon. I then have a configuration JFrame that is created in a separate class from the menu class, but is created when the user clicks the config button in the menu panel. In the configuration JFrame the user can select a picture from the hard disk and it saves the path inside an Access database. This picture is the picture for the ImageIcon in the menu JFrame. I cant get it to update the picture in the menu frame when a user changes the picture, it will only do it when the program is restarted. I do have a method that updates picture and when it is called it updates the picture, but I cannot call it from the Configuration class i don't think sense the menu class has been started from main and the config class has been started from the listener in the menu class. any ideas. I hope this makes sense with what I am tring to do. Thanks.
 
You need to pass the menu JFrame into the configuration JFrame class (probably in the constructor) so that you can call its methods.
 
Im not sure how I would do that. let see if i can explain it better.

my code:

public class menuClass(){
//constructor

//methods to create JFrame and buttons

public void updatePic(){
//code to update picture
}

//listener for Configuration button that calls other class
...
Config con = new Config();
...
}

with code set up like this, i dont know how from the config class I can call the updatePic method, or access the JFrame.

I cannot pass the menuClass as a parameter can I?

Any help is much appreciated.
 
Yes, you can pass the menuClass as a parameter to the Config constructor:
Code:
Config con = new Config(this);

You just specify (menuClass menu) as a parameter for your Config constructor and save it off in a class variable there so you can use it later.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top