Java 类型AbstractButton中的方法addActionListener(ActionListener)不适用于参数
我的代码中有这个错误,我是一个初学者,我不知道为什么在其他程序中单击时执行的动作事件/动作是成功的,但在这一个程序中,我使用了相同的模式,它给了我这个错误,有人能帮我吗 当我试图在用户单击登录时放置事件时,错误通过createfirstframe类发生Java 类型AbstractButton中的方法addActionListener(ActionListener)不适用于参数,java,mysql,Java,Mysql,我的代码中有这个错误,我是一个初学者,我不知道为什么在其他程序中单击时执行的动作事件/动作是成功的,但在这一个程序中,我使用了相同的模式,它给了我这个错误,有人能帮我吗 当我试图在用户单击登录时放置事件时,错误通过createfirstframe类发生 package cinema; import java.awt.*; import java.sql.*; import javax.swing.*; //Create a simple GUI window public cla
package cinema;
import java.awt.*;
import java.sql.*;
import javax.swing.*;
//Create a simple GUI window
public class createframe {
public static void createfirstframe() {
JFrame Frame1;
Frame1 = new JFrame("Customer");
Frame1.setSize(1000,1000);
Frame1.setLayout(new GridLayout(5, 2));
JLabel login1= new JLabel(" Type your IDs to log in the Cinema interface !");
Frame1.add(login1);
JTextField logintextarea1 = new JTextField(30);
JPasswordField loginpassword1 = new JPasswordField("");
JLabel login = new JLabel("Login customer (pseudo) : ");
JLabel password= new JLabel("password : ");
Frame1.add(login);
Frame1.add(logintextarea1);
Frame1.add(password);
Frame1.add(loginpassword1);
Frame1.add(new JLabel(new ImageIcon("/Users/elouazraouiayoub/Downloads/AtTheMovies.jpg")));
JButton btnGet = new JButton("Log in");
Frame1.add(btnGet);
btnGet.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection c= DriverManager.getConnection("jdbc:mysql://localhost:8889/test","root","");
Statement stmt =c.createStatement();
String sql="Select * from usersID where Username='"+logintextarea1.getText()+"' and password='"+loginpassword1.getText()+"'";
ResultSet rs =stmt.executeQuery(sql);
if(rs.next())
{
//connexion and checking established
}
else
{
JOptionPane.showMessageDialog(null, "Username/password Error","ERROR", JOptionPane.ERROR_MESSAGE);
logintextarea1.setText(null);
loginpassword1.setText(null);
logintextarea1.requestFocusInWindow();
}
}
catch (Exception e1) {e1.printStackTrace();}
Frame1.setVisible(true);
}});
}
public static void createsecondframe()
{
JFrame Frame2;
Frame2 = new JFrame("employee");
Frame2.setSize(1000,1000);
Frame2.setLayout(new GridLayout(5, 2));
JLabel login2= new JLabel(" Type your employee IDs to log in the Cinema interface !");
Frame2.add(login2);
JTextField logintextarea2 = new JTextField(30);
JPasswordField loginpassword2 = new JPasswordField("");
JLabel login = new JLabel("Login employee (pseudo) : ");
JLabel password= new JLabel("password : ");
Frame2.add(login);
Frame2.add(logintextarea2);
Frame2.add(password);
Frame2.add(loginpassword2);
Frame2.add(new JLabel(new ImageIcon("/Users/elouazraouiayoub/Downloads/AtTheMovies.jpg")));
Frame2.setVisible(true);
}}
这是我的课程
非常感谢尝试导入
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
开始时,再次运行它