Fórum Codigo para o botão "Sair", fechando só o formulario #564810
09/04/2009
0
c.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
Edson Amorim
Curtir tópico
+ 0Posts
09/04/2009
Juan Damasceno
Gostei + 0
09/04/2009
Rodrigo Scorsatto
public void botaoX (){
addWindowListener (new WindowAdapter () {
public void windowClosing (WindowEvent e) {
//caixa de dialogo retorna um inteiro
setVisible (false); // sai da tela em que esta
Principal.getInstance ().setVisible (true); //vai para a tela que você quiser...
}
});Gostei + 0
09/04/2009
André Britto
private void formFrameClosing(javax.swing.event.InternalFrameEvent evt) {
this.fechar();
}
private void fechar(){
if(javax.swing.JOptionPane.showConfirmDialog(null,"Deseja Fechar?","ATENÇÂO ",javax.swing.JOptionPane.YES_NO_OPTION )==0){
this.dispose();
}
}
Gostei + 0
09/04/2009
Henrique Freitas
Gostei + 0
09/04/2009
Edson Amorim
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Relatorio1 extends JFrame {
JLabel l;
JTextField t;
JButton b, c;
Initial janela;
public Relatorio1() {
super("Consulta Contatos por Nome");
Container tela = getContentPane();
setLayout(null);
l = new JLabel("Nome.: ");
l.setBounds(20, 20, 100, 20);
t = new JTextField(50);
t.setBounds(20, 50, 250, 20);
b = new JButton("Exibir Relatório");
b.setBounds(20, 90, 130, 20);
c = new JButton("Sair");
c.setBounds(200, 90, 70, 20);
tela.add(l);
tela.add(t);
tela.add(b);
tela.add(c);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
janela = new Initial();
janela.buscaTabela(t.getText());
janela.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
janela.setVisible(true);
}
});
// c.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e){
// System.exit(0);
// }
// });
//*****************************************
//** inseri o seu código aqui...
private void Relatorio1Closing(javax.swing.event.InternalFrameEvent evt) {
this.fechar();
}
private void fechar(){
if(javax.swing.JOptionPane.showConfirmDialog(null,"Deseja Fechar?","ATENÇÂO ",javax.swing.JOptionPane.YES_NO_OPTION )==0){
this.dispose();
}
}
//**** Mas está dando erro **********
//******************************************
setSize(300, 200);
setVisible(true);
setLocationRelativeTo(null);
}
public static void main(String[] args) {
Relatorio1 app = new Relatorio1();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Gostei + 0
09/04/2009
Marcos
//c.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e){
// System.exit(0);
// }
// });
Gostei + 0
09/04/2009
Edson Amorim
Gostei + 0
09/04/2009
Marcos
public static void main(String[] args) {
Relatorio1 app = new Relatorio1();
//app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Gostei + 0