📄 loginui.java
字号:
package MYclass;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
public class LoginUI implements ActionListener
{
JFrame j;
JLabel jLabel1;
JLabel jLabel2;
JLabel jLabel3;
JLabel jLabel4;
JButton jButton3;
JButton jButton2;
JButton jButton1;
JPasswordField jPasswordField1;
JTextField jTextField1;
Icon i;
public LoginUI()
{
j=new JFrame("JQQ");
j.setLayout(null);
j.setSize(340,220);
jLabel1 = new JLabel();
jLabel1.setBounds(2, 3, 352, 210);
i=new ImageIcon("tu/d.jpg");
jLabel1.setIcon(i);
jButton3 = new JButton();
jButton3.setBounds(245, 160, 68, 21);
jButton3.setText("登录");
jButton3.setForeground(Color.BLUE);
jButton3.addActionListener(this);
jButton2 = new JButton();
jButton2.setBounds(126, 160, 71, 21);
jButton2.setText("取消");
jButton2.setForeground(Color.BLUE);
jButton2.addActionListener(this);
jButton1 = new JButton();
jButton1.setBounds(13, 160, 66, 21);
jButton1.setText("注册");
jButton1.setForeground(Color.BLUE);
jButton1.addActionListener(this);
jPasswordField1 = new JPasswordField();
jPasswordField1.setBounds(113, 111, 173, 22);
jLabel3 = new JLabel();
jLabel3.setText("QQ密码:");
jLabel3.setForeground(Color.GREEN);
jPasswordField1.addActionListener(this);
jLabel3.setBounds(17, 111, 49, 21);
jTextField1 = new JTextField();
jTextField1.setBounds(113, 72, 173, 22);
jTextField1.addActionListener(this);
jLabel2 = new JLabel();
jLabel2.setText("QQ帐号:");
jLabel2.setForeground(Color.GREEN);
jLabel2.setBounds(17, 72, 77, 23);
jLabel4 = new JLabel();
jLabel4.setText("制作人: 李杰");
jLabel4.setForeground(Color.GREEN);
jLabel4.setBounds(216, 0, 132, 31);
j.add(jLabel2);
j.add(jTextField1);
j.add(jLabel3);
j.add(jLabel4);
j.add(jPasswordField1);
j.add(jButton1);
j.add(jButton2);
j.add(jButton3);
j.add(jLabel1);
j.setResizable(false);
j.setLocation(300,200);
j.setVisible(true);
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("注册"))
{
j.dispose();
RegisterUI zc=new RegisterUI();
}
else if(e.getActionCommand().equals("取消"))
{
System.exit(0);
}
else if(e.getActionCommand().equals("登录"))
{
if(jTextField1.getText().equals("")||jPasswordField1.getPassword().equals(""))
{
j.dispose();
JOptionPane.showMessageDialog(null,"用户名与密码不为空","警告",JOptionPane.INFORMATION_MESSAGE);
LoginUI lo=new LoginUI();
}
else
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection co=DriverManager.getConnection("jdbc:odbc:lj","sa","");
String str="select * from zhuce where QQ=? and mima=?";
PreparedStatement sta=co.prepareStatement(str);
sta.setString(1, jTextField1.getText());
sta.setString(2,jPasswordField1.getText());
ResultSet re=sta.executeQuery();
if(re.next())
{
j.dispose();
JOptionPane.showMessageDialog(null,"登录成功","消息",JOptionPane.INFORMATION_MESSAGE);
ClientmainUI gf=new ClientmainUI();
}
else
{
j.dispose();
JOptionPane.showMessageDialog(null,"用户名或密码错误,请重新输入!!!","警告",JOptionPane.ERROR_MESSAGE);
LoginUI lo=new LoginUI();
}
re.close();
co.close();
}
catch(Exception e1)
{
e1.printStackTrace();
}
}
}
}
public static void main(String[] args)
{
LoginUI l = new LoginUI();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -