alguem da uma luz, acho q o problema ta no action q eu nao to muito bom =/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.sql.PreparedStatement.*;
public class Menu extends JFrame implements ActionListener {
MeuJTextField mjtfCodigo = new MeuJTextField(20,true);
MeuJTextField mjtfNome = new MeuJTextField(20,true);
MeuJTextField mjtfEndereco = new MeuJTextField(20,false);
JButton jbOK = new JButton("OK");
JButton jbCancela = new JButton("Cancelar");
Connection con;
public static void main (String args[]) {
Menu menu = new Menu();
}
public Menu() {
getContentPane().setLayout(new GridLayout(4,4));
getContentPane().add(new JLabel("Codigo:"));
getContentPane().add(mjtfCodigo);
getContentPane().add(new JLabel("Nome:"));
getContentPane().add(mjtfNome);
getContentPane().add(new JLabel("Endereco:"));
getContentPane().add(mjtfEndereco);
getContentPane().add(jbOK);
getContentPane().add(jbCancela);
setSize(300,150);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
try {
Class.forName("org.firebirdsql.jdbc.FBDriver");
con = DriverManager.getConnection("jdbc:firebirdsql:localhost:C:\\TESTE.GDB","SYSDBA","masterkey");
PreparedStatement ps = con.prepareStatement("insert into cliente values(?,?,?)");
ps.setInt(1,Integer.parseInt(mjtfCodigo.getText()));
ps.setString(2,mjtfNome.getText());
ps.setString(3,mjtfEndereco.getText());
if (e.getSource() == jbOK){
ps.executeUpdate();
JOptionPane.showMessageDialog(this,"Query executada com sucesso");
}
if (e.getSource() == jbCancela){
}
con.close();
}
catch(Exception event){
JOptionPane.showMessageDialog(null,"Conexão não estabelecida ","Vifique o sistema",JOptionPane.ERROR_MESSAGE);
}
}
class MeuJTextField extends JTextField implements FocusListener {
private boolean obrigatorio = false;
public MeuJTextField(int tamanho, boolean obrigatorio) {
super(tamanho);
this.obrigatorio = obrigatorio;
if (obrigatorio)
setBackground(Color.yellow);
else
setBackground(Color.white);
addFocusListener(this);
}
public void focusGained(FocusEvent e) {
setBackground(Color.orange);
}
public void focusLost(FocusEvent e) {
if (obrigatorio)
setBackground(Color.yellow);
else
setBackground(Color.white);
}
}
class MeuPainelComboBox extends JPanel {
private JComboBox jcb = new JComboBox();
public MeuPainelComboBox() {
super();
setLayout(new GridLayout(1,2));
add(jcb);
}
}
}