📄 logon.java~28~
字号:
package homerealtysystem;import java.awt.*;import com.borland.jbcl.layout.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author 刘庆 * @version 1.0 */public class LogOn extends JFrame { XYLayout xYLayout1 = new XYLayout(); JButton jButton1 = new JButton(); JTextField UserName = new JTextField(); JPasswordField UserPassword = new JPasswordField(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JPanel MainApp_jPanel = new JPanel(); JButton jButton2 = new JButton(); JButton jButton3 = new JButton(); String CurrentUser = new String(); public void setCurrentUser(String name) { CurrentUser = name; } public String getCurrentUser() { return CurrentUser; } public LogOn() throws HeadlessException { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { jButton1.setBounds(new Rectangle(246, 83, 84, 27)); jButton1.setFont(new java.awt.Font("Dialog", 0, 16)); jButton1.setText("登陆"); jButton1.addActionListener(new LogOn_jButton1_actionAdapter(this)); xYLayout1.setWidth(486); xYLayout1.setHeight(293); this.setDefaultCloseOperation(HIDE_ON_CLOSE); this.setLocale(java.util.Locale.getDefault()); this.setResizable(true); this.setState(Frame.ICONIFIED); this.setTitle("用户登陆界面"); this.getContentPane().setLayout(xYLayout1); UserName.setFont(new java.awt.Font("Dialog", 0, 16)); UserName.setToolTipText(""); UserName.setSelectionStart(11); UserName.setText("崔宁宁"); UserName.setBounds(new Rectangle(99, 47, 131, 30)); UserPassword.setFont(new java.awt.Font("Dialog", 0, 16)); UserPassword.setEditable(true); UserPassword.setText("111"); UserPassword.setBounds(new Rectangle(98, 82, 131, 28)); jLabel1.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel1.setText("用户名"); jLabel1.setBounds(new Rectangle(27, 55, 67, 22)); jLabel2.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel2.setText("密码"); jLabel2.setBounds(new Rectangle(25, 82, 45, 28)); MainApp_jPanel.setLayout(null); jButton2.setBounds(new Rectangle(246, 49, 84, 27)); jButton2.setFont(new java.awt.Font("Dialog", 0, 16)); jButton2.setVerifyInputWhenFocusTarget(true); jButton2.setText("注册"); jButton2.addActionListener(new LogOn_jButton2_actionAdapter(this)); jButton3.setBounds(new Rectangle(314, 209, 86, 33)); jButton3.setFont(new java.awt.Font("Dialog", 0, 16)); jButton3.setText("退出"); jButton3.addActionListener(new LogOn_jButton3_actionAdapter(this)); this.getContentPane().add(MainApp_jPanel, new XYConstraints(10, 8, 469, 280)); MainApp_jPanel.add(jLabel1, new XYConstraints(66, 88, 46, 19)); MainApp_jPanel.add(jLabel2, new XYConstraints(64, 126, 55, -1)); MainApp_jPanel.add(UserName, new XYConstraints(134, 86, 122, 25)); MainApp_jPanel.add(UserPassword, new XYConstraints(134, 120, 124, 28)); MainApp_jPanel.add(jButton2, null); MainApp_jPanel.add(jButton1, new XYConstraints(276, 85, 73, 27)); MainApp_jPanel.add(jButton3, null); pack(); } void jButton1_actionPerformed(ActionEvent e) { ErrorMessage errmsg=new ErrorMessage(); //错误处理 ResultSet rs=null; //定义结果集rs,存放结果集 DBbean db=new DBbean(); //实例化dbBean用于查询 String user=UserName.getText(); String password=UserPassword.getText(); //sql查询语句,用于核查用户和密码 String sql="select * from 用户信息表 where 用户名字='"+user+"' and 密码='"+password+"'"; //检查输入是否为空 if(!errmsg.isEmpty(user)&&!errmsg.isEmpty(password)) { try{ rs=db.executeQuery(sql); //执行查询 if(rs.next()) //判断结果集是否存在 { this.setCurrentUser(user); GetFrmLocation gfl=new GetFrmLocation();//实例化GetFrmLocatin UserMainFrame frame=new UserMainFrame(CurrentUser); //实例化下一个frame gfl.get_location(frame); //让frame显示在屏幕中心 frame.show(); //frame的显示 this.dispose(); //本窗体的退出// JOptionPane.showMessageDialog(null, "合法用户!"); } else{ //错误提示 JOptionPane.showMessageDialog(null, "密码或用户名错误!"); } }catch(SQLException ex) { System.err.println("sql error!"); } } else{ JOptionPane.showMessageDialog(null, "输入不能为空清输入合理数据!"); } } void jButton3_actionPerformed(ActionEvent e) { System.exit(0); //退出系统 } void jButton2_actionPerformed(ActionEvent e) { GetFrmLocation gfl=new GetFrmLocation();//实例化GetFrmLocatin RegisterFrame frame=new RegisterFrame(); //实例化下一个frame gfl.get_location(frame); //让frame显示在屏幕中心 frame.show(); //frame的显示 this.dispose(); //本窗体的退出 }}class LogOn_jButton1_actionAdapter implements java.awt.event.ActionListener { LogOn adaptee; LogOn_jButton1_actionAdapter(LogOn adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}class LogOn_jButton3_actionAdapter implements java.awt.event.ActionListener { LogOn adaptee; LogOn_jButton3_actionAdapter(LogOn adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton3_actionPerformed(e); }}class LogOn_jButton2_actionAdapter implements java.awt.event.ActionListener { LogOn adaptee; LogOn_jButton2_actionAdapter(LogOn adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -