📄 enterframe.java
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
public class EnterFrame extends JFrame implements ActionListener
{
JLabel lbuser=new JLabel("用户名 "),
lbpassword=new JLabel(" 密码 ");
JTextField tauser=new JTextField();
JPasswordField papassword=new JPasswordField();
JButton btnenssure=new JButton("确定 ");
JButton btnexit=new JButton(" 取消 ");
JFrame f=new JFrame("学生信息管理系统登录框 ");
public EnterFrame()
{
Container cp=f.getContentPane();
cp.setBackground(Color.green);
btnenssure.setBackground(Color.orange);
btnexit.setBackground(Color.orange);
cp.setLayout(null);
cp.add(lbuser);lbuser.setBounds(40,40,100,30);
cp.add(tauser);tauser.setBounds(140,40,150,30);
cp.add(lbpassword);lbpassword.setBounds(40,90,100,30);
cp.add(papassword);;papassword.setBounds(140,90,150,30);
cp.add(btnenssure);;btnenssure.setBounds(80,180,100,30);
cp.add(btnexit);btnexit.setBounds(200,180,100,30);
btnexit.addActionListener(this);
btnenssure.addActionListener(this);
f.setSize(400,300);
f.setLocation(300,300);
f.setVisible(true);
}
public static void main(String args[])
{ String JDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String conURL="jdbc:odbc:Xsstudent";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e)
{
System.out.println("加载驱动失败");}
new EnterFrame();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnexit) System.exit(0);
if(e.getSource()==btnenssure)
{
try{
Connection con=DriverManager.getConnection("jdbc:odbc:Xsstudent");
Statement s=con.createStatement();
String str="select * from user where userid='"+tauser.getText().trim()+"'and password='"+papassword.getText().trim()+"'";
ResultSet rs=s.executeQuery(str);
if(rs.next())
{new MainFrame();
f.setVisible(false);
}
else
{JOptionPane.showMessageDialog(this,"抱歉!用户名不对或者密码错误,请重新输入");
tauser.setText(null);
papassword.setText(null);
}
}
catch(Exception ee)
{ System.out.println("SQLException 错误信息 "+ee.getMessage() ); }
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -