Galera boa noite,
preciso de ajudar tenho um codigo e gostaria que quando eu clicar no botao Salvar os dados do cadastro fosse para um Banco de Dados.
Mas o problema é que nao consigo fazer isso, alguém pode me ajudar.
desde ja agradeço.
package loja;
import javax.swing.;
import java.awt.;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.event.*;
import javax.swing.text.MaskFormatter;
import java.text.ParseException;
public class cadastro extends JFrame implements ActionListener
{
JLabel lb_titulo;
JLabel lb_nome;
JLabel lb_rg;
JTextField tf_nome;
JTextField tf_rg;
JButton bt_salvar, bt_sair, bt_novo;
JFormattedTextField format_rg;
MaskFormatter mascara_rg;
public cadastro()
{
setTitle("FICHA DE CADASTRO");
setLocation(380, 30);
setSize(380, 400);
getContentPane().setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
getContentPane().setBackground(Color.DARK_GRAY);
lb_titulo = new JLabel("CADASTRAR CLIENTE");
lb_nome = new JLabel("NOME :");
lb_rg = new JLabel("RG :");
tf_nome = new JTextField("",50);
tf_rg = new JTextField("",50);
tf_rg = new JFormattedTextField(mascara_rg);
bt_salvar = new JButton("SALVAR");
bt_salvar .setMnemonic(KeyEvent.VK_S);
bt_sair = new JButton("SAIR");
bt_sair .setMnemonic(KeyEvent.VK_S);
bt_novo = new JButton("NOVO CADASTRO");
bt_novo .setMnemonic(KeyEvent.VK_N);
lb_titulo .setBounds(120, 20, 200, 40);
lb_nome .setBounds(10, 70, 80, 30);
lb_rg .setBounds(10, 100, 80, 30);
tf_nome .setBounds(70, 75, 200, 20);
tf_rg .setBounds(70, 105, 80, 20);
bt_salvar .setBounds(10, 300, 90, 30);
bt_sair .setBounds(250, 300, 90, 30);
bt_novo .setBounds(105, 300, 140, 30);
try
{
mascara_rg = new MaskFormatter("########-#");
}
catch(ParseException excep)
{
}
format_rg = new JFormattedTextField(mascara_rg);
format_rg .setBounds(70, 105, 80, 20);
lb_titulo .setForeground(Color.RED);
lb_nome .setForeground(Color.BLUE);
lb_rg .setForeground(Color.BLUE);
bt_salvar .setForeground(Color.BLUE);
bt_sair .setForeground(Color.BLUE);
bt_novo .setForeground(Color.BLUE);
getContentPane().add(format_rg );
getContentPane().add(lb_titulo);
getContentPane().add(lb_nome);
getContentPane().add(lb_rg);
getContentPane().add(tf_nome);
getContentPane().add(tf_rg);
getContentPane().add(bt_salvar);
getContentPane().add(bt_sair);
getContentPane().add(bt_novo);
bt_salvar.addActionListener(this);
bt_sair .addActionListener(this);
bt_novo .addActionListener(this);
}
public static void main(String args[])
{
JFrame obj_cadastro = new cadastro();
obj_cadastro.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == bt_sair)
System.exit(0);
}
}