Olá, pessoal.
Estou fazendo um sistema de controle de mercadorias apenas para estudo. Estou utilizando o modelo MVC e para o desenvolvimento da interface, estou usando Swing. Quero fazer um JInternalFrame para a tela de cadastro. Não sei o que acontece, porque eu já a adicionei a um JDeskotPane e ela não aparece. No Windows, a JinternalFrame Cadastro de Cliente aparece e some muito rápido, já no Mac, ele aparece muito afastada para a esquerda. Gostaria que alguém me desse uma luz sobre onde estou errando, por favor.
Abaixo está o código do meu frame:
package view;
import java.awt.event.ActionListener;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class TesteGUI extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public JDesktopPane desktop;
public JMenuBar barraDeMenu;
public JMenu menuClientes;
public JMenu menuMercadorias;
public JMenu menuVendas;
public JMenu menuRelatorios;
public JMenu menuAjuda;
public JMenuItem cadastroDeClientes;
public JMenuItem cadastroDeMercadorias;
public JMenuItem buscaDeClientes;
public JMenuItem buscaDeMercadorias;
public JMenuItem efetuarVenda;
public JMenuItem buscarVenda;
public JMenuItem sobre;
public JMenuItem sair;
public TesteGUI() {
this.setTitle("SIGEME - Sistema de Gest?o de Mercadorias - Cerealista Carneiro LTDA");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
desktop = new JDesktopPane();
setContentPane(desktop);
barraDeMenu = criaMenu();
this.setJMenuBar(barraDeMenu);
this.setVisible(true);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
}
public JMenuBar criaMenu() {
barraDeMenu = new JMenuBar();
menuClientes = new JMenu("Clientes");
menuMercadorias = new JMenu("Mercadorias");
menuVendas = new JMenu("Vendas");
menuRelatorios = new JMenu("RelatÛrios");
menuAjuda = new JMenu("Ajuda");
cadastroDeClientes = new JMenuItem("Cadastrar");
cadastroDeMercadorias = new JMenuItem("Cadastrar");
buscaDeClientes = new JMenuItem("Buscar");
buscaDeMercadorias = new JMenuItem("Buscar");
efetuarVenda = new JMenuItem("Efetuar Venda");
buscarVenda = new JMenuItem("Buscar Venda");
sobre = new JMenuItem("Sobre o SIGEME");
sair = new JMenuItem("Sair");
cadastroDeClientes.setEnabled(true);
cadastroDeMercadorias.setEnabled(false);
buscaDeClientes.setEnabled(false);
buscaDeMercadorias.setEnabled(false);
buscarVenda.setEnabled(false);
efetuarVenda.setEnabled(false);
sobre.setEnabled(false);
sair.setEnabled(true);
menuClientes.add(cadastroDeClientes);
menuClientes.add(buscaDeClientes);
menuClientes.add(sair);
menuMercadorias.add(cadastroDeMercadorias);
menuMercadorias.add(buscaDeMercadorias);
menuVendas.add(efetuarVenda);
menuVendas.add(buscarVenda);
menuAjuda.add(sobre);
barraDeMenu.add(menuClientes);
barraDeMenu.add(menuMercadorias);
barraDeMenu.add(menuVendas);
barraDeMenu.add(menuRelatorios);
barraDeMenu.add(menuAjuda);
return barraDeMenu;
}
public void adicionarOuvinte(ActionListener ouvinte) {
this.cadastroDeClientes.addActionListener(ouvinte);
this.sair.addActionListener(ouvinte);
//this.mcCadastro.addActionListener(ouvinte);
//this.mcSair.addActionListener(ouvinte);
}
public static void main(String[] args) {
Teste gui = new TesteGUI();
}
}
package view;
import java.awt.Color;
import java.awt.Container;
import java.awt.TextField;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.text.ParseException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.text.MaskFormatter;
public class CadastroClienteGUI extends JInternalFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public JButton botaoSair;
public JButton botaoLimparCampos;
// public JButton botaoExcluirCliente;
// public JButton botaoConsultaCliente;
public JButton botaoIncluirCliente;
// public JButton botaoAlterarCliente;
public TextField tfCodigoCliente;
public TextField tfNomeCliente;
public TextField tfEnderecoCliente;
public TextField tfBairroCliente;
public TextField tfCidadeCliente;
// cpf precisa? precisa implementar! cpf/cnpj
public JFormattedTextField tfDataDeCadastroCliente, tfTelefoneCliente,
tfCelularCliente, tfCEPCliente;
public MaskFormatter data, telefone, celular, CEP;
public JLabel labelCodigoCliente, labelNomeCliente, labelSexoCliente,
labelEnderecoCliente, labelBairroCliente, labelCidadeCliente,
labelEstadoCliente, labelCEPCliente, labelTelefoneCliente,
labelCelularCliente, labelDataDeCadastroCliente;
public JComboBox comboSexoCliente, comboEstadoCliente;
public JPanel jpanel;
public CadastroClienteGUI() {
//super("Cadastro de Clientes", true, true, true, true);
setTitle("Cadastro de Clientes");
setaCombos();
setaBotoes();
setaCampos();
setaCamposFormatados();
setaLabels();
jpanel = new JPanel();
//jpanel.setLayout(new FlowLayout().LEFT);
jpanel.add(labelCodigoCliente);
jpanel.add(tfCodigoCliente);
jpanel.add(labelNomeCliente);
jpanel.add(tfNomeCliente);
jpanel.add(labelEnderecoCliente);
jpanel.add(tfEnderecoCliente);
jpanel.add(labelBairroCliente);
jpanel.add(tfBairroCliente);
jpanel.add(labelCidadeCliente);
jpanel.add(tfCidadeCliente);
jpanel.add(labelEstadoCliente);
jpanel.add(comboEstadoCliente);
jpanel.add(labelCEPCliente);
jpanel.add(tfCEPCliente);
jpanel.add(labelSexoCliente);
jpanel.add(comboSexoCliente);
jpanel.add(labelTelefoneCliente);
jpanel.add(tfTelefoneCliente);
jpanel.add(labelCelularCliente);
jpanel.add(tfCelularCliente);
jpanel.add(labelDataDeCadastroCliente);
jpanel.add(tfDataDeCadastroCliente);
Container container = getContentPane();
container.add(jpanel);
this.setVisible(true);
}
private void setaLabels() {
labelCodigoCliente = new JLabel("CÛdigo do cliente:");
labelNomeCliente = new JLabel("Nome completo:");
labelSexoCliente = new JLabel("Sexo:");
labelEnderecoCliente = new JLabel("EndereÁo:");
labelBairroCliente = new JLabel("Bairro:");
labelCidadeCliente = new JLabel("Cidado:");
labelEstadoCliente = new JLabel("Estado:");
labelCEPCliente = new JLabel("CEP:");
labelTelefoneCliente = new JLabel("Telefone:");
labelCelularCliente = new JLabel("Celular:");
labelDataDeCadastroCliente = new JLabel("Data de cadastro:");
}
private void setaCamposFormatados() {
try {
data = new MaskFormatter("##/##/####");
} catch (ParseException e) {
e.printStackTrace();
}
try {
telefone = new MaskFormatter("##-####-####");
} catch (ParseException e) {
e.printStackTrace();
}
try {
celular = new MaskFormatter("##-####-####");
} catch (ParseException e) {
e.printStackTrace();
}
try {
CEP = new MaskFormatter("#####-###");
} catch (ParseException e) {
e.printStackTrace();
}
tfDataDeCadastroCliente = new JFormattedTextField(data);
tfTelefoneCliente = new JFormattedTextField(telefone);
tfCelularCliente = new JFormattedTextField(celular);
tfCEPCliente = new JFormattedTextField(CEP);
data.setValidCharacters("[telefone removido]");
telefone.setValidCharacters("[telefone removido]");
celular.setValidCharacters("[telefone removido]");
CEP.setValidCharacters("[telefone removido]");
tfDataDeCadastroCliente.setColumns(9);
tfCelularCliente.setColumns(9);
tfTelefoneCliente.setColumns(9);
tfDataDeCadastroCliente.setColumns(7);
}
private void setaCampos() {
tfCodigoCliente = new TextField(30);
tfNomeCliente = new TextField(30);
tfEnderecoCliente = new TextField(30);
tfBairroCliente = new TextField(30);
tfCidadeCliente = new TextField(30);
}
private void setaBotoes() {
botaoSair = new JButton("Sair");
botaoLimparCampos = new JButton("Limpar Campos");
botaoIncluirCliente = new JButton("CadastrarCliente");
}
public void setaCombos() {
String sexoCliente[] = { "Masculino", "Feminino" };
comboSexoCliente = new JComboBox(sexoCliente);
comboSexoCliente.setBackground(Color.white);
comboSexoCliente.setForeground(Color.black);
String comboUFCliente[] = { "AC", "AL", "AP", "AM", "BA", "CE", "DF",
"ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE",
"PI", "RR", "RO", "RJ", "RN", "RS", "SC", "SP", "SE", "TO" };
comboEstadoCliente = new JComboBox(comboUFCliente);
comboEstadoCliente.setBackground(Color.white);
comboEstadoCliente.setForeground(Color.black);
}
public void adicionarOuvinteCliente1(ActionListener ouvinteIncluirCliente1) {
this.botaoSair.addActionListener(ouvinteIncluirCliente1);
this.botaoLimparCampos.addActionListener(ouvinteIncluirCliente1);
this.botaoIncluirCliente.addActionListener(ouvinteIncluirCliente1);
}
public void adicionarOuvinteClienteItem(ItemListener ouvinteCliente) {
comboSexoCliente.addItemListener(ouvinteCliente);
comboEstadoCliente.addItemListener(ouvinteCliente);
}
public void limparCampos() {
// TODO Auto-generated method stub
}
}
e aqui, o trecho da controladora que chama a tela de cadastro do cliente:
private void createTelaDeCadastro() {
IncluirClienteController clienteController = new IncluirClienteController();
clienteController.guiCli.setVisible(true);
gui.desktop.add(clienteController.guiCli);
}
Ah, gostaria de saber também como faço para deixar os campos na tela de cadastro listados um abaixo do outro?
Desde já obrigada pela atenção!
[]'s