private JLabel lblNome,lblEndereco,lblNum,lblTelRes,lblTelCel,lblRG,lblCPF;
private JTextField txtNome,txtEndereco,txtNum;
private JPanel painel;
private JFormattedTextField txtCPF,txtRG,txtTelRes,txtTelCel;
private JButton btnNovo,btnAlterar,btnSalvar,btnAnterior,btnProximo,btnSair,btnExcluir;
public frmCadCliente() {
// modelagem da tela
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
int a=710;//largura
int b = 400;//altura
setSize(a,b);
setLocation(380,200);
setResizable (false);
setTitle ("Cadastro de Cliente");
// definindo gerenciador de layout
setLayout(new BorderLayout());
//criando um painel e colocando uma borda em volta da tela
painel = new JPanel(new ParagraphLayout());
add("Center",painel);
painel.setBorder(BorderFactory.createTitledBorder( "Dados do Cliente"));
// menus
JMenuBar barra = new JMenuBar();
setJMenuBar(barra);
//inicio
JMenu inicio = new JMenu("Inicio");
inicio.setMnemonic('i');
ImageIcon iconeArq = new ImageIcon(ClassLoader.getSystemResource("images/arquivo.png"));
inicio.setIcon(iconeArq);
barra.add(inicio);
// ajuda
JMenu ajuda = new JMenu("Ajuda");
setJMenuBar(barra);
ajuda.setMnemonic('a');
ImageIcon iconeArq1 = new ImageIcon(ClassLoader.getSystemResource("images/help.png"));
ajuda.setIcon(iconeArq1);
barra.add(ajuda);
JMenu sobre = new JMenu("Sobre");
setJMenuBar(barra);
sobre.setMnemonic('S');
ImageIcon iconeArq4 = new ImageIcon(ClassLoader.getSystemResource("images/livro.png"));
sobre.setIcon(iconeArq4);
barra.add(sobre);
// item novo
JMenuItem item = new JMenuItem("Novo");
inicio.add(item);
item.setName("btnNovo");
item.addActionListener(this);
ImageIcon iconeNovo_A = new ImageIcon(ClassLoader.getSystemResource("images/novo.gif"));
item.setIcon(iconeNovo_A);
inicio.add(item);
//item salvar
JMenuItem item1 = new JMenuItem("Salvar");
inicio.add(item1);
item1.setName("btnSalvar");
item1.addActionListener(this);
ImageIcon iconeNovo_Ae = new ImageIcon(ClassLoader.getSystemResource("images/ok.png"));
item1.setIcon(iconeNovo_Ae);
inicio.add(item1);
// item alterar
JMenuItem item2 = new JMenuItem("Alterar");
inicio.add(item2);
item2.setName("btnAlterar");
item2.addActionListener(this);
ImageIcon iconeNovo_As = new ImageIcon(ClassLoader.getSystemResource("images/page_edit.png"));
item2.setIcon(iconeNovo_As);
inicio.add(item2);
// item excluir
JMenuItem item3 = new JMenuItem("Excluir");
inicio.add(item3);
item3.setName("btnExcluir");
item3.addActionListener(this);
ImageIcon iconeNovo_Aa = new ImageIcon(ClassLoader.getSystemResource("images/excluir_1.gif"));
item3.setIcon(iconeNovo_Aa);
inicio.add(item3);
// item sair
JMenuItem item4 = new JMenuItem("Sair");
inicio.add(item4);
item4.setName("btnSair");
item4.addActionListener(this);
ImageIcon iconeNovo_Ab = new ImageIcon(ClassLoader.getSystemResource("images/fechar_sair.gif"));
item4.setIcon(iconeNovo_Ab);
inicio.add(item4);
inicio.insertSeparator(4);
// campos e nomes
lblNome = new JLabel ("Nome :");
lblNome .setFont (new Font ("Arial new",Font.BOLD,18));
txtNome = new JTextField (25);
txtNome .setFont (new Font ("Arial new",Font.BOLD,18));
txtNome.setToolTipText("Digite o Nome Completo do Cliente");
txtNome.setEditable(false);
lblEndereco = new JLabel ("Endereço :");
lblEndereco.setFont (new Font ("Arial new",Font.BOLD,18));
txtEndereco = new JTextField (25);
txtEndereco.setFont (new Font ("Arial new",Font.BOLD,18));
txtEndereco.setToolTipText("Digite o Endereço do Cliente");
txtEndereco.setEditable(false);
lblNum = new JLabel ("Número:");
lblNum.setFont (new Font ("Arial new",Font.BOLD,18));
txtNum = new JTextField (25);
txtNum.setFont (new Font ("Arial new",Font.BOLD,18));
txtNum.setToolTipText("Digite o Número da Casa do Cliente");
txtNum.setEditable(false);
lblCPF = new JLabel ("CPF :");
lblCPF.setFont (new Font ("Arial new",Font.BOLD,18));
lblRG = new JLabel ("RG :");
lblRG.setFont (new Font ("Arial new",Font.BOLD,18));
lblTelRes = new JLabel ("Telefone Residencial:");
lblTelRes.setFont (new Font ("Arial new",Font.BOLD,18));
lblTelCel = new JLabel ("Telefone Celular:");
lblTelCel.setFont (new Font ("Arial new",Font.BOLD,18));
MaskFormatter CPF = null;
MaskFormatter RG = null;
MaskFormatter Residencial = null;
MaskFormatter Celular = null;
try {
CPF = new MaskFormatter("###.###.###-## ");
RG = new MaskFormatter ("#.###-###-# ");
Celular= new MaskFormatter ("####-#### ");
Residencial = new MaskFormatter("####-#### ");
} catch (ParseException e) {
e.printStackTrace();
}
txtCPF = new JFormattedTextField(CPF);
txtCPF.setEditable(false);
txtCPF .setFont (new Font ("Arial new",Font.BOLD,18));
txtCPF.setToolTipText("Digite o CPF Completo do Cliente");
txtRG= new JFormattedTextField (RG);
txtRG.setEditable(false);
txtRG .setFont (new Font ("Arial new",Font.BOLD,18));
txtRG.setToolTipText("Digite o RG Completo do Cliente");
txtTelCel= new JFormattedTextField (Celular);
txtTelCel.setEditable(false);
txtTelCel.setFont (new Font ("Arial new",Font.BOLD,18));
txtTelCel.setToolTipText("Digite o Telefone Celular do Cliente");
txtTelRes = new JFormattedTextField (Residencial);
txtTelRes.setEditable(false);
txtTelRes.setFont (new Font ("Arial new",Font.BOLD,18));
txtTelRes.setToolTipText("Digite o Telefone Residencial do Cliente");
setLayout(new FlowLayout());
//botões
// instanciando botao anterior
JButton btnAnterior= new JButton();
btnAnterior.setName ("btnAnterior");
btnAnterior.setFont((new java.awt.Font("Arial New", 0, 18)));
btnAnterior.setToolTipText("Pressione para Voltar");
ImageIcon iconeAnterior = new ImageIcon(ClassLoader.getSystemResource("images/esquerda.png"));
btnAnterior.setIcon(iconeAnterior);
btnAnterior.setEnabled(true);
btnAnterior.addActionListener(this);
add(btnAnterior);
JButton btnNovo= new JButton("Novo");
btnNovo.setName ("btnNovo");
ImageIcon iconeNovo =new ImageIcon(ClassLoader.getSystemResource("images/novo.gif"));
btnNovo.setIcon(iconeNovo);
btnNovo.setFont((new java.awt.Font("Times new roman", 0, 22)));
btnNovo.setToolTipText("Pressione para cadastrar o cliente");
btnNovo.addActionListener(this);
add(btnNovo);
//criando,dando nome ,dando acao ao botao e addicionando ao painel
JButton btnAlterar= new JButton("Alterar");
btnAlterar.setName ("btnAlterar");
ImageIcon iconeAlterar = new ImageIcon(ClassLoader.getSystemResource("images/page_edit.png"));
btnAlterar.setIcon(iconeAlterar);
btnAlterar.setFont((new java.awt.Font("Times new roman", 0, 22)));
btnAlterar.setToolTipText("Pressione para alterar ou modificar dados do cliente");
btnAlterar.setEnabled(true);
btnAlterar.addActionListener(this);
add(btnAlterar);
//botao excluir
JButton btnExcluir= new JButton("Excluir");
ImageIcon iconeExcluir = new ImageIcon(ClassLoader.getSystemResource("images/excluir_1.gif"));
btnExcluir.setIcon(iconeExcluir);
btnExcluir.setFont((new java.awt.Font("Times new roman", 0, 22)));
btnExcluir.setToolTipText("Pressione excluir o cliente");
btnExcluir.setName ("btnExcluir");
btnExcluir.setEnabled(true);
btnExcluir.addActionListener(this);
add(btnExcluir);
//criando,dando nome ,dando acao ao botao e addicionando ao painel
JButton btnSalvar= new JButton("Salvar");
ImageIcon iconeSalvar = new ImageIcon(ClassLoader.getSystemResource("images/ok.png"));
btnSalvar.setIcon(iconeSalvar);
btnSalvar.setFont((new java.awt.Font("Times new roman", 0, 22)));
btnSalvar.setToolTipText("Pressione para salvar um cliente");
btnSalvar.setName ("btnSalvar");
btnSalvar.setEnabled(true);
btnSalvar.addActionListener(this);
add(btnSalvar);
// criando,dando nome ,dando acao ao botao e addicionando ao painel
JButton btnSair= new JButton("Sair");
btnSair.setName ("btnSair");
ImageIcon iconeSair = new ImageIcon(ClassLoader.getSystemResource("images/fechar_sair.gif"));
btnSair.setIcon(iconeSair);
btnSair.setFont((new java.awt.Font("Times new roman", 0, 22)));
btnSair.setToolTipText("Pressione para sair");
btnSair.addActionListener(this);
add(btnSair);
// instanciando botao proximo
JButton btnProximo= new JButton();
btnProximo.setName ("btnProximo");
ImageIcon iconeProximo = new ImageIcon(ClassLoader.getSystemResource("images/direita.png"));
btnProximo.setIcon(iconeProximo);
btnProximo.setFont((new java.awt.Font("Times new roman", 0, 22)));
btnProximo.setToolTipText("Pressione para avançar");
btnProximo.setEnabled(true);
btnProximo.addActionListener(this);
add(btnProximo);
// painel que adiciona os componentes
painel.add(lblNome,ParagraphLayout.NEW_PARAGRAPH);
painel.add(txtNome);
painel.add(lblEndereco,ParagraphLayout.NEW_PARAGRAPH);
painel.add(txtEndereco);
painel.add(lblNum,ParagraphLayout.NEW_PARAGRAPH);
painel.add(txtNum);
painel.add (lblTelRes,ParagraphLayout.NEW_PARAGRAPH);
painel.add(txtTelRes);
painel.add(lblTelCel,ParagraphLayout.NEW_PARAGRAPH);
painel.add(txtTelCel);
painel.add(lblCPF,ParagraphLayout.NEW_PARAGRAPH);
painel.add(txtCPF);
painel.add(lblRG,ParagraphLayout.NEW_PARAGRAPH);
painel.add(txtRG);
setVisible(true);
}
public static void main(String[] args) {
frmCadCliente telaCadPro = new frmCadCliente();
}
public void actionPerformed(ActionEvent arg0) {
Component botao = (Component)arg0.getSource();
if (botao.getName().equals("btnSalvar")){
if (txtNome.getText().length() == 0){
JOptionPane.showMessageDialog(this, "Digite o NOME ","Atenção",JOptionPane.CANCEL_OPTION);
return;
}
if (txtEndereco.getText().length() == 0){
JOptionPane.showMessageDialog(this, "Digite o ENDEREÇO ","Atenção",JOptionPane.CANCEL_OPTION);
return;
}
if (txtNum.getText().length() == 0){
JOptionPane.showMessageDialog(this, "Digite o NÚMERO DA CASA ","Atenção",JOptionPane.CANCEL_OPTION);
return;
}
if (txtCPF.getText().replaceAll("\\.*-*", "").trim().length() == 0){
JOptionPane.showMessageDialog(this, "Digite o CPF ","Atenção",JOptionPane.CANCEL_OPTION);
return;
}
if (txtRG.getText().replaceAll("\\.*-*", "").trim().length() == 0){
JOptionPane.showMessageDialog(this, "Digite o RG ","Atenção",JOptionPane.CANCEL_OPTION);
return;
}
}
[b]if (botao.getName().equals("btnNovo")){[/b]
txtNome.setEditable(true);
txtEndereco.setEditable(true);
txtNum.setEditable(true);
txtTelRes.setEditable(true);
txtTelCel.setEditable(true);
txtCPF.setEditable(true);
txtRG.setEditable(true);
txtNome.requestFocus();
[b]btnAlterar.setEnabled(!btnNovo.isSelected()); [/b]
}
if(botao.getName().equals("btnSair")){
System.exit(0);
}
}
public void update(Observable arg0, Object arg1) {
// TODO Auto-generated method stub
}