📄 jf_login.java
字号:
package appgdzc.view;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.border.EtchedBorder;
import java.awt.Color;
import javax.swing.border.Border;
import java.awt.GridLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.FlowLayout;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyAdapter;
import appgdzc.AppMain;
import javax.sql.DataSource;
import appgdzc.tools.InitContext;
import appgdzc.tools.GlobaBean;
public class JF_Login extends JFrame {
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
Border border1 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
Color.white, new Color(148, 145, 140));
GridLayout gridLayout1 = new GridLayout();
JLabel jLabel1 = new JLabel();
JTextField jTuser = new JTextField();
JLabel jLabel2 = new JLabel();
JPasswordField jPassconf = new JPasswordField();
JLabel jLabel3 = new JLabel();
JPasswordField jPass = new JPasswordField();
JPanel jPanel2 = new JPanel();
FlowLayout flowLayout1 = new FlowLayout();
JButton jBlogin = new JButton();
JButton jBexit = new JButton();
JPanel jPanel3 = new JPanel();
JLabel jLabel4 = new JLabel();
java.sql.Connection con = null;
java.sql.Statement stmt = null;
java.sql.ResultSet rest = null;
String id = null;
String pass = null;
String pass1 = null;
FlowLayout flowLayout2 = new FlowLayout();
AppMain appmain = null;
appgdzc.model.facadeQuery facade = null;
public JF_Login() {
try {
this.setSize(new Dimension(380, 200));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
jbInit();
setVisible(true);
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(borderLayout1);
this.setResizable(false);
this.setTitle("系统登录");
jLabel1.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
jLabel1.setText("用户ID:");
jTuser.setPreferredSize(new Dimension(6, 17));
jTuser.setText("");
jTuser.addKeyListener(new JF_Login_jTuser_keyAdapter(this));
jLabel2.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
jLabel2.setText("用户口令:");
jPassconf.setPreferredSize(new Dimension(6, 17));
jPassconf.setText("");
jPassconf.addKeyListener(new JF_Login_jPassconf_keyAdapter(this));
jLabel3.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
jLabel3.setText("重复口令:");
jPass.setPreferredSize(new Dimension(6, 17));
jPass.setText("");
jPass.addKeyListener(new JF_Login_jPass_keyAdapter(this));
jPanel2.setLayout(flowLayout1);
jBlogin.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
jBlogin.setPreferredSize(new Dimension(83, 30));
jBlogin.setText("系统登录");
jBlogin.addActionListener(new JF_Login_jBlogin_actionAdapter(this));
jBexit.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
jBexit.setPreferredSize(new Dimension(83, 30));
jBexit.setText("系统退出");
jBexit.addActionListener(new JF_Login_jBexit_actionAdapter(this));
flowLayout1.setAlignment(FlowLayout.RIGHT);
borderLayout1.setHgap(2);
borderLayout1.setVgap(5);
gridLayout1.setVgap(5);
jPanel3.setLayout(flowLayout2);
jLabel4.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
jLabel4.setText("用户姓名:");
flowLayout2.setAlignment(FlowLayout.LEFT);
this.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
jPanel1.add(jLabel1);
jPanel1.add(jTuser);
jPanel1.add(jLabel2);
jPanel1.add(jPass);
jPanel1.add(jLabel3);
jPanel1.add(jPassconf);
this.getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
jPanel2.add(jBlogin);
jPanel2.add(jBexit);
this.getContentPane().add(jPanel3, java.awt.BorderLayout.NORTH);
jPanel3.add(jLabel4, null);
gridLayout1.setColumns(2);
gridLayout1.setRows(3);
jPanel1.setBorder(border1);
jPanel1.setLayout(gridLayout1);
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
//设置初始化连接
GlobaBean bean = new GlobaBean();
bean.getFacadeObject();
DataSource ds = null;
facade = bean.facadeQueryObject;
ds = (DataSource) bean.dataSource;
if (ds == null) System.exit(0);
con = ds.getConnection();
stmt = con.createStatement();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
javax.swing.plaf.metal.MetalLookAndFeel aa = new javax.swing.plaf.metal.MetalLookAndFeel();
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (Exception exception) {
exception.printStackTrace();
}
new JF_Login();
}
});
}
public void jBexit_actionPerformed(ActionEvent actionEvent) {
// new java.awt.Font("",);
int result = JOptionPane.showOptionDialog(null,"是否真的退出用户登录?","系统提示",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
null,new String[] {"是","否"},"否");
if (result == JOptionPane.YES_OPTION) {
try{
con.close();
System.exit(0);
}catch(java.sql.SQLException sql){
sql.printStackTrace();
}
}
}
public void jBlogin_actionPerformed(ActionEvent actionEvent) {
id = jTuser.getText().trim();
pass = new String(jPass.getPassword());
pass1 = new String(jPassconf.getPassword());
//System.out.println("id " + id + "pass = " + pass + " passconf = " + pass1);
if (id == null || id.length() <= 0 ){
JOptionPane.showMessageDialog(null,"输入用户ID不能为空,请重新输入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
jTuser.requestFocus();
return;
}
if(pass == null || pass.length() <= 0 ){
JOptionPane.showMessageDialog(null,"输入用户口令不能为空,请重新输入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
jPass.requestFocus();
return;
}
if(pass1 == null || pass1.length() <= 0 ){
JOptionPane.showMessageDialog(null,"输入重复口令不能为空,请重新输入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
jPassconf.requestFocus();
return;
}
if(!pass.equals(pass1)){
JOptionPane.showMessageDialog(null,"两次输入的口令不一致,请重新输入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
jPassconf.requestFocus();
return;
}
String sqlStr = null;
sqlStr = "select pass from t_user where id = '" + id + "'";
java.util.Collection collection = null;
java.util.Vector vdata = null;
String _pass = null;
try{
collection = facade.getQueryObject(sqlStr);
vdata = (java.util.Vector)collection.iterator().next();
_pass = String.valueOf(vdata.get(0)).trim();
System.out.println("_pass" + _pass);
jPass.requestFocus();
}catch(java.rmi.RemoteException remote){
JOptionPane.showMessageDialog(null,"输入的口令不正确,请重新输入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
remote.printStackTrace();
}
if (pass.equals(_pass)){
System.out.println("appmain =" + AppMain.class.isInstance(this));
if (AppMain.class.isInstance(appmain)){
return;
}else{
appmain = new AppMain();
}
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(false);
}else{
JOptionPane.showMessageDialog(null,"输入的口令不正确,请重新输入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
jPass.requestFocus();
return;
}
}
public void jTuser_keyPressed(KeyEvent keyEvent) {
if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER){
String sqlStr = null;
sqlStr = "select name from t_user where id = '" + jTuser.getText().trim() + "'";
java.util.Collection collection = null;
java.util.Vector vdata = null;
try{
collection = facade.getQueryObject(sqlStr);
if (collection.isEmpty()){
JOptionPane.showMessageDialog(null,"输入的用户ID不存在,请重新输入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
return;
}
vdata = (java.util.Vector)collection.iterator().next();
jLabel4.setText("用户姓名:" + vdata.get(0));
jPass.requestFocus();
}catch(java.rmi.RemoteException remote){
JOptionPane.showMessageDialog(null,"输入的用户ID不存在,请重新输入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
remote.printStackTrace();
}
}
}
public void jPass_keyPressed(KeyEvent keyEvent) {
if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER){
jPassconf.requestFocus();
}
}
public void jPassconf_keyPressed(KeyEvent keyEvent) {
if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER){
// ActionEvent mm = new ActionEvent(object ,int ,String );
ActionEvent event = new ActionEvent(jBlogin,0,"");
this.jBlogin_actionPerformed(event);
}
}
}
class JF_Login_jTuser_keyAdapter extends KeyAdapter {
private JF_Login adaptee;
JF_Login_jTuser_keyAdapter(JF_Login adaptee) {
this.adaptee = adaptee;
}
public void keyPressed(KeyEvent keyEvent) {
adaptee.jTuser_keyPressed(keyEvent);
}
}
class JF_Login_jPass_keyAdapter extends KeyAdapter {
private JF_Login adaptee;
JF_Login_jPass_keyAdapter(JF_Login adaptee) {
this.adaptee = adaptee;
}
public void keyPressed(KeyEvent keyEvent) {
adaptee.jPass_keyPressed(keyEvent);
}
}
class JF_Login_jPassconf_keyAdapter extends KeyAdapter {
private JF_Login adaptee;
JF_Login_jPassconf_keyAdapter(JF_Login adaptee) {
this.adaptee = adaptee;
}
public void keyPressed(KeyEvent keyEvent) {
adaptee.jPassconf_keyPressed(keyEvent);
}
}
class JF_Login_jBlogin_actionAdapter implements ActionListener {
private JF_Login adaptee;
JF_Login_jBlogin_actionAdapter(JF_Login adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jBlogin_actionPerformed(actionEvent);
}
}
class JF_Login_jBexit_actionAdapter implements ActionListener {
private JF_Login adaptee;
JF_Login_jBexit_actionAdapter(JF_Login adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jBexit_actionPerformed(actionEvent);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -