📄 loginframe.java
字号:
package org.wuhang.login;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import org.jfree.report.JFreeReportBoot;
import org.signsmile.view.MainFrame;
public class LoginFrame extends JFrame{
private static final long serialVersionUID = 2954714600302412066L;
private JPanel msgPanel;
private JPanel loginPanel,loginPanel1,loginPanel2,loginPanel3;
private JLabel jlbuserName,jlbuserPwd;
private JTextField jtfuserName;
private JPasswordField jpfuserPwd;
private JButton jbtLogin,jbtCancel;
public LoginFrame(){
msgPanel = new JPanel();
Font font = new Font("Optima,sans-serif", Font.ITALIC, 20);
JLabel jlbMsg = new JLabel("成教数据库管理系统");
jlbMsg.setForeground(Color.BLUE);
jlbMsg.setFont(font);
msgPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
msgPanel.add(jlbMsg);
loginPanel = new JPanel();
jlbuserName = new JLabel("用户:");
jlbuserPwd = new JLabel("密码:");
jtfuserName = new JTextField(10);
jpfuserPwd = new JPasswordField(10);
jbtLogin = new JButton("登录");
jbtCancel = new JButton("取消");
loginPanel1 = new JPanel();
loginPanel1.setLayout(new FlowLayout(FlowLayout.CENTER));
loginPanel1.add(jlbuserName);
loginPanel1.add(jtfuserName);
loginPanel2 = new JPanel();
loginPanel2.setLayout(new FlowLayout(FlowLayout.CENTER));
loginPanel2.add(jlbuserPwd);
loginPanel2.add(jpfuserPwd);
loginPanel3 = new JPanel();
loginPanel3.setLayout(new FlowLayout(FlowLayout.RIGHT));
loginPanel3.add(jbtLogin);
loginPanel3.add(jbtCancel);
loginPanel.setLayout(new BorderLayout());
loginPanel.add(loginPanel1,BorderLayout.NORTH);
loginPanel.add(loginPanel2,BorderLayout.CENTER);
loginPanel.add(loginPanel3,BorderLayout.SOUTH);
//登录
jbtLogin.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
submit();
}});
//取消
jbtCancel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dispose();
}
});
this.setTitle("成教数据库管理");
this.getContentPane().add(msgPanel,BorderLayout.NORTH);
this.getContentPane().add(loginPanel,BorderLayout.CENTER);
this.setSize(300,200);
this.setLocation(this.getToolkit().getScreenSize().width / 2
- this.getWidth() / 2, this.getToolkit().getScreenSize().height
/ 2 - this.getHeight() / 2);
this.setResizable(false);
this.getRootPane().setDefaultButton(jbtLogin);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void submit(){
char user_Pwd[] = jpfuserPwd.getPassword();
String user_name = jtfuserName.getText();
String s_user_Pwd = new String();
if("".equals(user_name)){
JOptionPane.showMessageDialog(null, "请输入登录账户", "提示",
JOptionPane.PLAIN_MESSAGE);
}
else if(user_Pwd.length==0){
JOptionPane.showMessageDialog(null, "请输入密码", "提示",
JOptionPane.PLAIN_MESSAGE);
}
else{
for(int i=0;i<user_Pwd.length;i++){
s_user_Pwd = s_user_Pwd + user_Pwd[i];
}
if(CheckUser.checkPwd(s_user_Pwd, user_name)){
setVisible(false);
JFreeReportBoot.getInstance().start();
MainFrame.GetMainFrame();
}
else{
JOptionPane.showMessageDialog(null, "账户或密码不正确", "提示",
JOptionPane.ERROR_MESSAGE);
//jtfuserName.setText("");
jpfuserPwd.setText("");
}
}
}
public static void main(String args[]){
new LoginFrame();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -