Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

Making ApplicationFrame stay open when calling from another class

Hi Experts,

I have this class that draws growth chart.
public class GrowthChart extends ApplicationFrame
{

        public GrowthChart(String s)
        {
                super(s);
                JPanel jpanel = createDemoPanel();
                jpanel.setPreferredSize(new Dimension(600, 700));
                setContentPane(jpanel);
        }

         public XYSeriesCollection createDataset(int sex)
        {
...
...
}

Open in new window


and I am calling this from another class...
public static GrowthData getGrowthChart(int sex,
			int age,
			double weight,
			double height
		
			) throws GrowthStatisticsException {
		GrowthData growthData = new GrowthData();
		try {
			growthData.sex = sex;
			growthData.age = age;
			growthData.weight = weight;
			growthData.height = height;
			//growthData.headCircumference = headCircumference;
			
			
				 GrowthChart growthChartDemo = new GrowthChart("Weight-for-age percentiles Growth Chart");
	                growthChartDemo.pack();
	                RefineryUtilities.centerFrameOnScreen(growthChartDemo);
	                growthChartDemo.setVisible(true);
	               // growthChartDemo.wait();
		
			
		
		} catch (Exception e) {
		...
		}
		
		
		return growthData;
	}

Open in new window


However, the frame doesn't stay open. (It opens and closes when exiting getGrowthChart(...) method.)

How do I make the frame stay open?

thanks,
0
dkim18
Asked:
dkim18
  • 4
  • 3
1 Solution
 
krakatoaCommented:
Hold a reference to it in the calling method's class somewhere, and hide, populate with data or show it instead when necessary.
0
 
dkim18Author Commented:
I've requested that this question be deleted for the following reason:

I found my own solution.
0
 
krakatoaCommented:
Well I object because the standard convention should be for you to post your solution, as this is how EE ensures assisting others in the future. Can you post your solution?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
krakatoaCommented:
In the meantime, here is code that shows and hides a JInternalFrame from another class.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Show extends JFrame implements ActionListener{

public JInternalFrame jif;

public JButton jbut;

private boolean showjif;

	Show(){

		this.setLayout(new GridLayout(0,1,0,0));
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

		jbut = new JButton();

		jif = new JInternalFrame();

		this.add(jif);
		
		this.add(jbut);

		jbut.addActionListener(this);

		this.setSize(new Dimension(500,350));

		this.setVisible(true);
		
	}


	public void actionPerformed(ActionEvent a){

		if(!(showjif)){
		jif.setVisible(true);
		showjif=!showjif;
		}

		else {jif.setVisible(false);showjif=!showjif;}
	}


}

Open in new window


Call with :

class DemShow{

public static void main(String[] args){
new Show().jbut.doClick();


}

}

Open in new window

0
 
dkim18Author Commented:
Actually, there was System.exit end of main method...I will give him point anyway then.
0
 
krakatoaCommented:
Actually, there was System.exit end of main method...I will give him point anyway then.

Where do you get the idea that there was a System.exit() call?
0
 
dkim18Author Commented:
I missed that line of code. that is all.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now