📄 login.java
字号:
package Student;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.Vector;
public class Login {
public static void main(String[] args) {
try {
Frame1 login = new Frame1();
} catch (Exception e) {
e.printStackTrace();
}
}
}
class Frame1 extends JFrame
{
static {
try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
} catch (Exception e) {
e.printStackTrace();
}
}
JButton jb1=new JButton();
JButton jb2=new JButton();
JButton jb3=new JButton();
JTextField tx1=new JTextField(12);
JPasswordField pw=new JPasswordField(12);
JLabel jl=new JLabel();
JLabel jl1=new JLabel();
JLabel jl2=new JLabel();
Container cp;
Container thiswindow=this;
public Frame1()
{
try{
jbinit();
}catch(Exception e){e.printStackTrace();}
}
private void jbinit()
{
cp=this.getContentPane();
cp.setLayout(new BorderLayout());
jb3.setText("退出");
jb3.setFont(new Font("SansSerif", Font.PLAIN, 12));
jb3.setForeground(Color.BLUE);
jb3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
jb1.setForeground(Color.BLUE);
jb1.setText("清除");
jb1.setFont(new Font("SansSerif", Font.PLAIN, 12));
jb1.setForeground(Color.BLUE);
jb2.setText("登入");
jb2.setFont(new Font("SansSerif", Font.PLAIN, 12));
jb2.setForeground(Color.BLUE);
jb2.addActionListener(new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
String password=pw.getText();
String userid=tx1.getText();
ResultSet rs;
String key=null;
try{
MyJDBC getkey=new MyJDBC();
rs=getkey.exceteQuery("SELECT sid,key FROM wengxinzhi.student where sid='"+userid+"'");
while (rs.next()) {
key=rs.getString(2);
}
if(key.equals(password))
{
StudentUI x=new StudentUI(userid,password);
thiswindow.setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null,"You ID Or Password is wrong");
}
rs.close();
}catch(Exception f){f.printStackTrace();
JOptionPane.showMessageDialog(null,"不能连接数据库");}
}
}
);
JPanel jp1=new JPanel();
jp1.add(jb1);
jp1.add(jb2);
jp1.add(jb3);
jb1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
pw.setText("");
tx1.setText("");
}
});
jl.setText("欢迎使用选课系统");
jl.setFont(new Font("SansSerif", Font.BOLD, 24));
jl.setForeground(Color.RED);
jl1.setText("用户ID");
jl1.setForeground(Color.GREEN);
jl2.setText("密码 ");
jl2.setForeground(Color.GREEN);
JPanel jpt1=new JPanel();
JPanel jpt2=new JPanel();
JPanel jp2=new JPanel();
jpt1.add(jl1);
jpt1.add(tx1);
jpt2.add(jl2);
jpt2.add(pw);
jp2.add(jpt1);
jp2.add(jpt2);
cp.add(jl,BorderLayout.NORTH);
cp.add(jp1,BorderLayout.SOUTH);
cp.add(jp2,BorderLayout.CENTER);
this.setSize(300,250);
this.setTitle("CRS-sutdent");
this.setLocation(350,250);
this.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -