Boa tarde
Ao programar apareceu um erro do action listener
public class Login extends JFrame implements ActionListener
Diz que a classe login não é abestrata.
Segue-se o código
import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Login extends JFrame implements ActionListener
{
private JLabel lbA;
private JLabel lbB;
private JTextField tfA;
private JTextField tfB;
private JButton btEntrar;
public Login ()
{
super ("Restaurante");
this. setLayout(new FlowLayout ());
lbA= new JLabel ("Utilizador:");
lbB= new JLabel ("Pass:");
tfA= new JTextField (10);
tfB= new JTextField (10);
btEntrar= new JButton ("Entrar");
this.add(lbA);
this.add(tfA);
this.add(lbB);
this.add(tfB);
this.add(btEntrar);
btEntrar.addActionListener(this);
this.setSize(225,150);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main (String args[])
{
Login jb = new Login ();
}
public void actionPerfmormed (ActionEvent e){
if(e.getSource()==btEntrar){
entrar();
}
}
private void entrar (){
final String JDBC_DRIVER="com.mysql.jdbc.Driver"; //nome do driver JDBC
final String DB_URL="jdbc:mysql://localhost/restaurante"; //URL da bade de dados
final String USER="root";
final String PASS="";
Connection conn=null;
Statement stmt=null;
try{
Class.forName("com.mysql.jdbc.Driver"); //registar driver JDBC;
conn=DriverManager.getConnection(DB_URL,USER ,PASS );
stmt=conn.createStatement();
String sql=" INSERT INTO restaurante.login VALUES ('" +tfA.getText() + "','"+tfB.getText() +"')";
stmt.executeUpdate(sql);
JOptionPane.showMessageDialog(this, "Registo Inserido!");
} catch (SQLException se){
//tratamentos de erros JDBC
se.printStackTrace();}
catch (Exception e){
//tratamento de erros de Class.forName
e.printStackTrace();}
finally{
//fecho dos recursos
try{
if (conn!=null)conn.close();
}catch (SQLException se){se.printStackTrace();}
}
}
}
O código ainda se encontra incompleto
Cumps
↧