0

I'm using this code

private void botaoGrafADMouseClicked(java.awt.event.MouseEvent evt) {
    try {
        boolean[] b=new boolean[8];
        if (Caixa9.isSelected()) b[0]=true; else b[0]=false;
        if (Caixa11.isSelected()) b[1]=true; else b[1]=false;
        if (Caixa10.isSelected()) b[2]=true; else b[2]=false;
        if (Caixa12.isSelected()) b[3]=true; else b[3]=false;
        b[4]=false;b[5]=false;b[6]=false;b[7]=false;
        final LineChartDemo1 demo = new LineChartDemo1("Leitura A/D",b,"outad.txt",4);
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);
    } catch (IOException ex) {
        Logger.getLogger(Comunicacao.class.getName()).log(Level.SEVERE, null, ex);
    }       
}

to call an graph interface. But, when I do this, every time I call the graph, it generates on new window and, if I close on of these windows, the whole program is closed. I'd want to know what am I doing wrong. How Can I avoid this (I would post a printscreen, but, as new user, I can't, it is on https://i.sstatic.net/4JLxQ.png I think

Edit: Image enter image description here

3 Answers 3

1

JFrame has a default close operation (i.e. what happens when you close the window using your window manager) of EXIT_ON_CLOSE. Use JFrame.setDefaultCloseOperation to set a different value.

Sign up to request clarification or add additional context in comments.

Comments

1

I don't know what the class LineChartDemo1 is, but you could probably set it as the content of a JDialog and call setDefaultCloseOperation (JDialog.DISPOSE_ON_CLOSE) on each dialog. This way, when the user closes the dialog, only that window will close, the others will remain open.

1 Comment

I just ran the code in a different JFrame so that when I close this, the program still running. Then, I used the public void windowClosing(final WindowEvent evt){ if(evt.getWindow() == this){ dispose(); } } not to close at the end.
0

I created a new netbeans JFrame and made reference to it like this:

InterfaceGrafico minhaInterface = new InterfaceGrafico("Leitura I/O",b,"outio.txt",8);

where the arguments where the same to generate the graph. In this "InterfaceGrafico" class:

public InterfaceGrafico(final String title,boolean[] b, String nomeArquivo, int col) {
try {
        initComponents();
        final LineChartDemo1 demo = new LineChartDemo1("Leitura I/O", b, "outio.txt", 8);
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);
    } catch (IOException ex) {
        Logger.getLogger(InterfaceGrafico.class.getName()).log(Level.SEVERE, null, ex);
    }

}

That means, I just shifted the code to another JFrame. I also commented the public void run method . Now I can close each graph generated without closing the whole application and the other generated graphs. In the "LineChart1" class, I added this

public void windowClosing(final WindowEvent evt){
    if(evt.getWindow() == this){
    dispose();
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.