| Author |
How i close my frame when i click in the button???
|
DanielCosta Sobrinho
Greenhorn
Joined: Jun 06, 2003
Posts: 19
|
|
Hi... I have a programa that have one button, when I click in the button open a frame and into the frame have a other jbutton and I want to close my frame when I click in the button... I tried this, but it closes my program all: btn4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); How I do??? to close my frame only...
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
|
yourframe.dispose()
|
 |
DanielCosta Sobrinho
Greenhorn
Joined: Jun 06, 2003
Posts: 19
|
|
Ocurred an error: local variable janela is accessed from within inner class; needs to be declared finaljanela.dispose(); what is this???
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
|
Can you post the code for you JFrame class you are trying to close.
|
 |
DanielCosta Sobrinho
Greenhorn
Joined: Jun 06, 2003
Posts: 19
|
|
Here... JDialog janela = new JDialog(this, botao.getText(),true); janela.getContentPane().setLayout(null); janela.setSize(550,150); janela.setLocation(200,200); janela.setResizable(false); /** Inserir dados sobre servi�os da tela aqui */ JLabel label1 = new JLabel ("URL: "+url); label1.setBounds(30,10,540,30); janela.getContentPane().add(label1); JLabel label2 = new JLabel ("TEMPO DE RESPOSTA: "+servico.getTempoResposta()+" segundos "); label2.setBounds(30,10,540,90); janela.getContentPane().add(label2); janela.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); //mostra subjanela janela.show();
|
 |
Dana Hanna
Ranch Hand
Joined: Feb 28, 2003
Posts: 227
|
|
A method-local variable (the dialog) is being accessed from within an anonymous class. You must declare the method-local variable as final: JDialog janela = new JDialog(this, botao.getText(),true); <becomes> final JDialog janela = new JDialog(this, botao.getText(),true); Then you'll be fine.
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
|
Dana is correct. Or you could make your JDialog variable a global variable. Either way will work. Then just call dispose() on the JDialog instead of System.exit(0) as this will cause the JVM to kill your application.
|
 |
DanielCosta Sobrinho
Greenhorn
Joined: Jun 06, 2003
Posts: 19
|
|
|
Thank's Danna and friends, you are correct....
|
 |
 |
|
|
subject: How i close my frame when i click in the button???
|
|
|