Estou com o seguinte problema: Tenho um jframe e vários jframe declarados no método construtor do JFrame. Até ai tudo bem. Porém ao adicionar um, o outro some quando tem o evento de clique. Quando eu mudo a posição, aparece um e para outro.
Por favor quem puder ajudar, é um projeto pra entregar até amanhã. Obrigado.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package aplicacao;
import formularios.CadUser;
import formularios.CadVeiculos;
import formularios.Disponiveis;
import formularios.PainelCadUsuario;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
*
* @author Gelson
*/
public class FrameGeral extends JFrame implements ActionListener {
/**
* @param args the command line arguments
*/
JButton botao, botao2, botao3, botao4;
CadVeiculos painelcadveiculo;
CadUser telauser;
Disponiveis veiculosdisp;
public FrameGeral() {
botao = new JButton("Cadastrar Clientes");
botao.setBounds(200,80,180,60);
botao.addActionListener(this);
botao2 = new JButton("Cadastrar Veiculo");
botao2.setBounds(200,160,180,60);
botao2.addActionListener(this);
botao3 = new JButton("Alugar Carro");
botao3.setBounds(200,240,180,60);
botao3.addActionListener(this);
botao4 = new JButton("Verificar Disponibilidade");
botao4.setBounds(200,320,180,60);
botao4.addActionListener(this);
// add botoes ao frame
this.add(botao);
this.add(botao2);
this.add(botao3);
this.add(botao4);
// adc paineis no frame geral
telauser = new CadUser();
painelcadveiculo = new CadVeiculos();
veiculosdisp = new Disponiveis();
//this.getContentPane().add(painelcadveiculo); // AQUI n ta indo
this.repaint();
//this.getContentPane().add(telauser); // ta indo aqui
this.getContentPane().add(veiculosdisp);
telauser.setVisible(false);
painelcadveiculo.setVisible(false);
veiculosdisp.setVisible(false);
this.setBackground(Color.yellow);
//this.getContentPane().add(painelalugarcarro);
//this.getContentPane().add(painelverificadisp);
this.pack();
this.setVisible(true);
this.setTitle("Locadora");
this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(botao)) {
botao.setVisible(false);
botao2.setVisible(false);
botao3.setVisible(false);
botao4.setVisible(false);
telauser.setVisible(true);
painelcadveiculo.setVisible(false);
}
if (e.getSource().equals(botao2)) {
botao.setVisible(false);
botao2.setVisible(false);
botao3.setVisible(false);
botao4.setVisible(false);
//new CadVeiculo().setVisible(true);
painelcadveiculo.setVisible(true);
telauser.setVisible(false);
}
if (e.getSource().equals(botao4)) {
botao.setVisible(false);
botao2.setVisible(false);
botao3.setVisible(false);
botao4.setVisible(false);
//new CadVeiculo().setVisible(true);
veiculosdisp.setVisible(true);
telauser.setVisible(false);
painelcadveiculo.setVisible(false);
}
}
}
Obrigado