📄 showframe.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class ShowFrame extends JFrame implements ActionListener
{
private JLabel name;
private JLabel password;
private JTextField myname;
private JPasswordField mypassword;
private JButton ok;
private JButton cancel;
private ResultSet rs;
private DBManager db=new DBManager();
public ShowFrame()
{
setTitle("登陆界面");
setSize(200,120);
Dimension screen=getToolkit().getScreenSize();
setLocation((screen.width-getSize().width)/2,(screen.height-getSize().height)/2);
setLayout(new GridLayout(3,2,2,2));
name=new JLabel(" 用户名");
password=new JLabel(" 密 码");
myname=new JTextField(16);
mypassword=new JPasswordField(16);
ok=new JButton("确定");
cancel=new JButton("取消");
getContentPane().add(name);
getContentPane().add(myname);
getContentPane().add(password);
getContentPane().add(mypassword);
getContentPane().add(ok);
getContentPane().add(cancel);
pack();
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
ok.addActionListener(this);
cancel.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent evt){
System.exit(0); //退出程序
}
}
);
show();
}
public void actionPerformed(ActionEvent e)
{
if (myname.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(ShowFrame.this,"用户名不能为空!");
return;
}
if(mypassword.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(ShowFrame.this,"密码不能为空!");
return;
}
String strSQL;
strSQL="select * from 用户表 where username='"+myname.getText().trim()+"' and password='"+mypassword.getText().trim()+"'";
rs=db.getResult(strSQL);
try{
if (rs.next())
{
this.dispose();
new BookManagerMain();
// String message="您的用户名:"+rs.getString("username")+"\n您的密码:"+rs.getString("password"); //消息字符串
// JOptionPane.showMessageDialog(null, message); //显示消息
}
else
{
JOptionPane.showMessageDialog(null,"用户名不存在或密码不正确!");
}
}
catch(SQLException ex1)
{
}
}
public static void main(String[] args)
{
new ShowFrame();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -