diogorsc Posted September 8, 2016 at 02:56 PM Report #598732 Posted September 8, 2016 at 02:56 PM (edited) 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 Edited September 8, 2016 at 03:32 PM by apocsantos geshi
Knitter Posted September 8, 2016 at 03:58 PM Report #598737 Posted September 8, 2016 at 03:58 PM (edited) O método que tens de implementar está mal escrito, é "actionPerformed" e não "actionPerfmormed" como tens no teu código. Edited September 8, 2016 at 03:58 PM by Knitter
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now