gpt4 book ai didi

Java - 航空公司预订按钮

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:24 24 4
gpt4 key购买 nike

我按下 Java 程序上的按钮,但它似乎什么也没做。我只是按下它们,什么也没有发生。我正在使用 Java 8。在 Eclipse 中。

不知道是不是数据库连接问题?如果是,我可能会直接使用 SQL。

这是登录页面的代码:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class login extends JFrame implements ActionListener{

JPanel pane = new JPanel();

ImageIcon imageicon = new ImageIcon ("res/login.png");
JLabel bg = new JLabel (" ", imageicon, JLabel.CENTER);
JLabel bg1 = new JLabel (new ImageIcon(""));


JTextField use1 = new JTextField();
JPasswordField pas1 = new JPasswordField();

JButton displayButton = new JButton("Login");
JButton cancelButton = new JButton("Cancel");

String search ="";
String searchP="";


// Select txt2= new Select();
Connection cn;
PreparedStatement ps;
Statement st;

public login(){
// pane.setBackground(Color.orange);
setContentPane (pane);
pane.setLayout (null);

//---------------------------------------------
pane.add(use1);
use1.setBounds(50,225, 190, 30);
use1.setToolTipText("Username");

pane.add(pas1);
pas1.setBounds(50,260, 190, 30);
pas1.setToolTipText("Password");
//---------------------------------------------
pane.add(displayButton);
displayButton.setBounds(60,300, 80, 25);
displayButton.addActionListener(this);


pane.add(cancelButton);
cancelButton.setBounds(150,300, 80, 25);
cancelButton.addActionListener(this);

//---------------------------------------------
pane.add(bg1);
bg1.setVisible(true);
bg1.setBounds (5,40,200,129);

pane.add(bg);
bg.setBounds (0,0,300,400);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

try{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
cn=DriverManager.getConnection("jdbc:ucanaccess://res/YOLO.accdb");
}catch(ClassNotFoundException a){
System.err.println("Failed to Load Driver");
a.printStackTrace();
}catch (SQLException a){
System.err.println("Unable to Connect");
a.printStackTrace();
}

}
public void actionPerformed (ActionEvent e){

if (e.getSource() ==displayButton){

search=use1.getText();
searchP=pas1.getText();


try{

if (!search.equals("")||!searchP.equals("")){

st= cn.createStatement();
ResultSet rs=st.executeQuery("SELECT * FROM Login WHERE UserN = '" + search+"'");

while(rs.next()){


searchP=rs.getString(2);

if(searchP.equalsIgnoreCase(pas1.getText())){

dispose();

JOptionPane.showMessageDialog (null, "Login Successful!! ");
main frame = new main ();
frame.setTitle ("YOLO Airline Ticketing & Hotel Reservation");
frame.setBounds(200,200,800,500);
frame.setVisible (true);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

st.close();
}
}
}catch(SQLException m){
System.out.println(m.getMessage());


}finally{

if (search.equals("")||searchP.equals("")){

if(search.equals("")){
JOptionPane.showMessageDialog(null,"Invalid Input!","Warning!",JOptionPane.INFORMATION_MESSAGE);
}
if(searchP.equals("")){
JOptionPane.showMessageDialog(null,"Invalid Password!","Warning!",JOptionPane.INFORMATION_MESSAGE);
}
}



}
}

}







public static void main(String args[]) {
login myframe = new login();
myframe.setBounds(400,280,300,400);
myframe.setTitle("YOLO Login");
myframe.setVisible(true);
myframe.setResizable(false);

}
}

最佳答案

尝试

displayButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {

}
});

关于Java - 航空公司预订按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37104723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com