Oi Galera, boa tarde !!!
Sou iniciante em java e fiz uma telinha bem simples pra cadastro de clientes, meu código é o seguinte:
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
public class Clientes extends JFrame {
JLabel lb_Nome, lb_Codigo, lb_Nascimento, lb_Endereço, lb_Numero,
lb_Complemento, lb_Bairro, lb_Cidade;
JTextField tf_Nome, tf_Codigo, tf_Nascimento, tf_Endereço, tf_Numero,
tf_Complemento, tf_Bairro, tf_Cidade, tf_Estado;
JButton bt_salvar, bt_fechar;
private JPanel contentPane;
private Clientes() {
setTitle("Locadora - Clientes");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(270, 200, 475, 350);// Mude aqui a para o tamanho desejado
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);// Absolute Layout
lb_Nome = new JLabel("Nome");
lb_Codigo = new JLabel("Código");
lb_Nascimento = new JLabel("Nascimento");
lb_Endereço = new JLabel("Endereço");
lb_Numero = new JLabel("Numero");
lb_Complemento = new JLabel("Complemento");
lb_Bairro = new JLabel("Bairro");
lb_Cidade = new JLabel("Cidade");
tf_Nome = new JTextField("");
tf_Codigo = new JTextField("");
tf_Nascimento = new JTextField("");
tf_Endereço = new JTextField("");
tf_Numero = new JTextField("");
tf_Complemento = new JTextField("");
tf_Bairro = new JTextField("");
tf_Cidade = new JTextField("");
bt_salvar = new JButton("Salvar");
bt_fechar = new JButton("Fechar");
tf_Codigo.setBounds(20, 30, 100, 20);
lb_Codigo.setBounds(20, 10, 80, 20);
tf_Nome.setBounds(20, 70, 320, 20);
lb_Nome.setBounds(20, 50, 150, 20);
tf_Numero.setBounds(350, 120, 100, 20);
lb_Numero.setBounds(350, 100, 100, 20);
tf_Nascimento.setBounds(350, 70, 100, 20);
lb_Nascimento.setBounds(350, 50, 80, 20);
tf_Endereço.setBounds(20, 120, 320, 20);
lb_Endereço.setBounds(20, 100, 150, 20);
tf_Complemento.setBounds(20, 170, 430, 20);
lb_Complemento.setBounds(20, 150, 250, 20);
tf_Bairro.setBounds(20, 220, 150, 20);
lb_Bairro.setBounds(20, 200, 80, 20);
tf_Cidade.setBounds(200, 220, 150, 20);
lb_Cidade.setBounds(200, 200, 80, 20);
bt_salvar.setBounds(20, 270, 150, 25);
bt_fechar.setBounds(200, 270, 150, 25);
getContentPane().add(tf_Nome);
getContentPane().add(tf_Codigo);
getContentPane().add(tf_Nascimento);
getContentPane().add(tf_Endereço);
getContentPane().add(tf_Numero);
getContentPane().add(tf_Complemento);
getContentPane().add(tf_Bairro);
getContentPane().add(tf_Cidade);
getContentPane().add(lb_Nome);
getContentPane().add(lb_Codigo);
getContentPane().add(lb_Nascimento);
getContentPane().add(lb_Endereço);
getContentPane().add(lb_Numero);
getContentPane().add(lb_Complemento);
getContentPane().add(lb_Bairro);
getContentPane().add(lb_Cidade);
getContentPane().add(bt_salvar);
getContentPane().add(bt_fechar);
}
public static void main(String[] args) {
new Clientes().setVisible(true);
}
}
A minha dúvida é a seguinte:
como eu faço pra quando clicar em salvar e ele salvar todos os dados, limpar todos os campos automaticamente????