是Aptech的学生,我们正在做很多项目,这是一个。 它涉及银行管理和使用。这是我的身份验证类,但我想要包含一个会话:
public class AuthenticationFrame {
public static void display() {
JFrame frame = new JFrame("JSoft");
JPanel panel1 = new JPanel(new GridBagLayout());
panel1.setOpaque(true);
panel1.setBackground(Color.BLACK);
JPanel panel2 = new JPanel(new GridBagLayout());
panel2.setOpaque(true);
panel2.setBackground(Color.GRAY);
JPanel panel3 = new JPanel(new BorderLayout());
panel3.setOpaque(true);
panel3.setBackground(Color.GRAY);
GridBagConstraints cons = new GridBagConstraints();
cons.insets = new Insets(5,3,5,3);
JLabel label1 = new JLabel("Enter Your name");
label1.setForeground(Color.BLUE);
JTextField field1 = new JTextField();
field1.setPreferredSize(new Dimension(130,20));
field1.setForeground(Color.RED);
JLabel label2 = new JLabel("Enter Your pin");
label2.setForeground(Color.BLUE);
JPasswordField field2 = new JPasswordField();
field2.setPreferredSize(new Dimension(130,20));
field2.setForeground(Color.RED);
JLabel lb = new JLabel("CB Banking");
JButton Rdbtn = new JButton("Proceed");
JButton Bkbtn = new JButton("<<");
cons.gridx = 0;
cons.gridy = 0;
panel1.add(label1, cons);
cons.gridx = 1;
cons.gridy = 0;
panel1.add(field1, cons);
cons.gridx = 0;
cons.gridy = 2;
panel1.add(label2, cons);
cons.gridx = 1;
cons.gridy = 2;
panel1.add(field2, cons);
cons.gridx = 1;
cons.gridy = 3;
panel1.add(Rdbtn, cons);
panel2.add(lb);
panel3.add(Bkbtn, BorderLayout.WEST);
Rdbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception er){
JOptionPane.showMessageDialog(null, er.getMessage());
}
try{
if(field1.getText().equals("") && field2.getText().equals("")){
JOptionPane.showMessageDialog(null, "no empty fields");
}
else{
Connection CBcon = DriverManager.getConnection("jdbc:mysql://localhost:3306/bankSystem_Db", "root", "elemie");
String username = field1.getText();
int pin = Integer.parseInt(field2.getText());
String query = "SELECT fname, pin FROM usertb WHERE fname = ? AND pin = ?";
PreparedStatement CBprep = CBcon.prepareStatement(query);
CBprep.setString(1, username);
CBprep.setInt(2, pin);
ResultSet CBrs = CBprep.executeQuery();
int CBresult = 0;
while(CBrs.next()){
CBresult+=1;
}
if(CBresult == 1){
UserFrame.monitor_three();
frame.dispose();
}
else{
JOptionPane.showMessageDialog(null,"Incorrect username or password");
field1.setText(null);
field2.setText(null);
}
CBrs.close();
CBprep.close();
}
}
catch(Exception er){
JOptionPane.showMessageDialog(null, er.getMessage());
}
}
});
Bkbtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ee){
Bsystem2.monitor_One();
frame.dispose();
}
});
frame.setSize(800, 500);
frame.setLocationRelativeTo ( null );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.add(panel1);
frame.getContentPane().add(panel2, BorderLayout.NORTH);
frame.getContentPane().add(panel3, BorderLayout.SOUTH);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
display();
}
});
}
}
这部分应该像atm一样工作。获取有关数据库中用户的所有信息。它假设打开我的userFrame类