Olha só…
Tenho a classe abaixo… Fiz o download do DERBY, descompactei-o num determinado diretório. Não estou conseguindo configurar o acesso ao banco para que eu possa inserir / consultar / alterar…
Tipo… Preciso saber como devo configurar… o q é preciso para conseguir acesso ao banco… se é necessário cria-lo…etc.
Sds.
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.text.MaskFormatter;
public class Clientes1 extends JFrame
{
public static void main(String[] args)
{
Clientes1 cli = new Clientes1();
cli.inicializaInterface();
}
// JLabel lblCodigo = new JLabel("Codigo:");
JLabel lblNome = new JLabel("Nome:");
JLabel lblCPF = new JLabel("CPF:");
JLabel lblRG = new JLabel("RG:");
JLabel lblDataNasc = new JLabel("Nasc.:");
JLabel lblSexo = new JLabel("Sexo:");
JLabel lblEndereco = new JLabel("Endereco:");
JLabel lblNum = new JLabel("N.o:");
JLabel lblBairro = new JLabel("Bairro:");
JLabel lblCidade = new JLabel("Cidade:");
JLabel lblUF = new JLabel("UF:");
JLabel lblEmail = new JLabel("E-Mail:");
JTextField txtEmail = new JTextField();
JTextField txtBairro = new JTextField();
JTextField txtCidade = new JTextField();
// JTextField txtCodigo = new JTextField();
JTextField txtCPF = new JTextField();
JTextField txtRG = new JTextField();
JTextField txtEndereco = new JTextField();
JTextField txtNum = new JTextField();
JTextField txtNome = new JTextField();
// JTextField txtDataNasc = new JTextField();
JFormattedTextField txtDataNasc = new JFormattedTextField();
JTextField txtUF = new JTextField();
// Cria ComboBox
String [] lstSexo = {null, "Masculino","Feminino"};
JComboBox cbSexo = new JComboBox(lstSexo);
JButton btnAdicionar = new JButton("Adicionar", new ImageIcon("D:/Meus documentos/Trabalhos/Java/imagens/l_add.gif"));
JButton btnAlterar = new JButton("AlTerar");
JButton btnConsultar = new JButton("Consultar", new ImageIcon("D:/Meus documentos/Trabalhos/Java/imagens/l_filesearch.gif"));
JButton btnLimpar = new JButton("Limpar", new ImageIcon("D:/Meus documentos/Trabalhos/Java/imagens/l_clear.gif"));
public void inicializaInterface()
{
//
JFrame f = new JFrame("Trabalho Semestral Java - Cadastro de Clientes");
f.setBounds(300, 200, 200, 150);
f.setSize(550,300);
Container cont = f.getContentPane();
cont.setLayout(null);
cbSexo.setEditable(false);
// lblCodigo.setBounds(45, 220, 50, 10);
// txtCodigo.setBounds(90, 215, 40, 20);
lblNome.setBounds(50, 05, 80, 20);
txtNome.setBounds(90, 05, 300, 20);
lblCPF.setBounds(60, 30, 80, 20);
txtCPF.setBounds(90, 30, 130, 20);
lblRG.setBounds(235, 30, 80, 20);
txtRG.setBounds(260, 30, 130, 20);
lblDataNasc.setBounds(400, 30, 80, 20);
txtDataNasc.setBounds(440, 30, 75, 20);
lblSexo.setBounds(55, 55, 60, 20);
cbSexo.setBounds(90, 55, 90, 20);
lblEndereco.setBounds(30, 80, 80, 20);
txtEndereco.setBounds(90, 80, 355, 20);
lblNum.setBounds(450, 80, 30, 20 );
txtNum.setBounds(475, 80, 40, 20);
lblBairro.setBounds(50, 105, 80, 20);
txtBairro.setBounds(90,105, 160,20);
lblCidade.setBounds(255, 105, 80, 20);
txtCidade.setBounds(300, 105, 160, 20);
lblUF.setBounds(465, 105, 80, 20);
txtUF.setBounds(485, 105, 30, 20);
lblEmail.setBounds(50, 130, 80, 20);
txtEmail.setBounds(90, 130, 300, 20);
btnAdicionar.setBounds(85, 180, 110, 20);
btnConsultar.setBounds(195, 180, 110, 20);
btnAlterar.setBounds(305, 180, 110, 20);
btnLimpar.setBounds(415, 180, 110, 20);
// cont.add(lblCodigo);
// cont.add(txtCodigo);
cont.add(lblNome);
cont.add(txtNome);
cont.add(lblCPF);
cont.add(txtCPF);
cont.add(lblRG);
cont.add(txtRG);
cont.add(lblDataNasc);
cont.add(txtDataNasc);
cont.add(lblSexo);
cont.add(cbSexo);
cont.add(lblEndereco);
cont.add(txtEndereco);
cont.add(lblNum);
cont.add(txtNum);
cont.add(lblBairro);
cont.add(txtBairro);
cont.add(lblCidade);
cont.add(txtCidade);
cont.add(lblUF);
cont.add(txtUF);
cont.add(lblEmail);
cont.add(txtEmail);
cont.add(btnAdicionar);
cont.add(btnConsultar);
cont.add(btnAlterar);
cont.add(btnLimpar);
this.formataData(txtDataNasc);
this.inicializaListener();
btnAdicionar.setMnemonic('A');
btnConsultar.setMnemonic('C');
btnAlterar.setMnemonic('T');
btnLimpar.setMnemonic('L');
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public void limpar()
{
this.txtNome.setText("") ;
this.txtCPF.setText("");
this.txtRG.setText("");
this.txtDataNasc.setText("");
this.cbSexo.setSelectedItem(null);
this.txtEndereco.setText("") ;
this.txtNum.setText("") ;
this.txtBairro.setText("") ;
this.txtCidade.setText("") ;
this.txtUF.setText("") ;
this.txtEmail.setText("") ;
this.btnAdicionar.setEnabled(true);
this.btnAlterar.setEnabled(true);
this.btnConsultar.setEnabled(true);
}
public void inicializaListener()
{
// Listener para Limpar tela ao clicar no botão Limpar
this.btnLimpar.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
limpar() ;
}
});
this.btnAdicionar.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(txtNome.getText().length() < 1)
{
JOptionPane.showMessageDialog(null,"Nome do Cliente deve ser informado!!!");
}
else
if (txtNome.getText().length() < 15)
{
JOptionPane.showMessageDialog(null,"Nome do Cliente informado deve conter pelo menos 15 Caracteres!!!");
}
else
{
JOptionPane.showMessageDialog(null,"Cliente " + txtNome.getText() + " foi adicionado!");
}
}
});
this.btnConsultar.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
btnAdicionar.setEnabled(false);
}
});
this.btnAlterar.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
}
public void formataData(JFormattedTextField data)
{
try
{
MaskFormatter formato = new MaskFormatter("##/##/####");
formato.install((JFormattedTextField) data);
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,
"EXCEPTION ERRO... NA FORMATAÇÃO DO NÚMERO ",
"Classe Utilidades",JOptionPane.WARNING_MESSAGE);
}
}
}