import java.sql.ResultSet;
import java.sql.SQLException;import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.KeyEvent;public class PassWord extends JFrame { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JTextField jTextField = null; private JPasswordField jPasswordField = null; private JButton jButton = null; private JLabel jLabel = null; private JLabel jLabel1 = null; private JLabel jLabel11 = null;
public static boolean flag=false;
String managername;
String managerpassword;
String outPut="";
/**
 * This is the default constructor
 */
public PassWord() {
super();
try{
initialize();
this.setSize(400, 300);
this.setLocation(400, 200);
this.show();
}catch(Exception e){
e.printStackTrace();
}

} /**
 * This method initializes this
 * 
 * @return void
 */
private void initialize() {

this.setContentPane(getJContentPane());
this.setSize(400, 300);
this.setTitle("宾馆管理系统");
} /**
 * This method initializes jContentPane
 * 
 * @return javax.swing.JPanel
 */
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel11 = new JLabel();
jLabel11.setBounds(new Rectangle(19, 145, 80, 35));
jLabel11.setFont(new Font("Dialog", Font.BOLD, 18));
jLabel11.setText("口 令");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(19, 87, 80, 35));
jLabel1.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
jLabel1.setFont(new Font("Dialog", Font.BOLD, 18));
jLabel1.setText("用户ID");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(99, 16, 180, 43));
jLabel.setFont(new Font("Dialog", Font.BOLD, 24));
jLabel.setText("系统管理员验证");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJTextField(), null);
jContentPane.add(getJPasswordField(), null);
jContentPane.add(getJButton(), null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(jLabel11, null);
}
return jContentPane;
} /**
 * This method initializes jTextField
 * 
 * @return javax.swing.JTextField
 */
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(123, 92, 147, 28));
}
return jTextField;
} /**
 * This method initializes jPasswordField
 * 
 * @return javax.swing.JPasswordField
 */
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setBounds(new Rectangle(126, 150, 143, 29));
}
return jPasswordField;
} /**
 * This method initializes jButton
 * 
 * @return javax.swing.JButton
 */
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(161, 217, 70, 25));
jButton.setText("验证");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String name=jTextField.getText().toString();
String password=jPasswordField.getText().toString();
if(!name.equals("")&&!password.equals("")){
String queryString="select * from HIMS_Manager";
ResultSet resultSet = null;
try{


try {

JDBCFile jdbc = new JDBCFile();
resultSet = jdbc.executeQuery(queryString);
} catch (Exception e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}

while(resultSet.next()){
    managername=resultSet.getString("name");
    managerpassword=resultSet.getString("password");
    System.out.println(managername+ managerpassword);
    if(managername.equals(name)&&managerpassword.equals(password)){
     HIMSMain himsmain=new HIMSMain();
     himsmain.setSize(750, 560);
     himsmain.show();
    
    
     break;
    }
    else{
     jTextField.setText("");
     jPasswordField.setText("");
    
    }
}

}catch (SQLException q) {
// TODO 自动生成 catch 块
q.printStackTrace();
}
}
else{
JOptionPane.showMessageDialog(null, "请输入完整信息","管理员登录",JOptionPane.PLAIN_MESSAGE);
}
}
});
}
return jButton;
}
public static void main(String[] arguments){
new PassWord();
}}import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.GridLayout;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class HIMSMain extends JFrame{ JMenuBar jMenubar_1=new JMenuBar();

JMenu jMenu_1=new JMenu();
JMenu jMenu_2=new JMenu();

JMenuItem jMenuItem_1=new JMenuItem();
JMenuItem jMenuItem_2=new JMenuItem();

JPanel jPanel=new JPanel();

GridLayout gridlayout_1=new GridLayout();

JButton jButton_1=new JButton();
JButton jButton_2=new JButton();

JPanel cardpanel_1=new JPanel();

CardLayout cardlayout_1=new CardLayout();

BorderLayout borderlayout_1=new BorderLayout();

JPanel jPanel_2=new JPanel();

BorderLayout borderlayout_2=new BorderLayout();

JTextField jTextField_1=new JTextField();


public HIMSMain(){
try{
jbInit();
}catch(Exception e){
e.printStackTrace();
}
}
private void jbInit() {
// TODO 自动生成方法存根
jMenubar_1.setDoubleBuffered(false);
jMenubar_1.setVerifyInputWhenFocusTarget(true);

this.setJMenuBar(jMenubar_1);
this.getContentPane().setLayout(borderlayout_1);
jMenu_2.setText("客户订房");
jMenuItem_1.setText("客户订房");
jMenuItem_1.addActionListener(new jMenuItem_1_actionAdapter(this));


}
public static void main(String[] arguments){
HIMSMain himsmain=new HIMSMain();
}

}

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【wangjunxu】截止到2008-07-17 17:07:51的历史汇总数据(不包括此帖):
    发帖的总数量:4                        发帖的总分数:160                      每贴平均分数:40                       
    回帖的总数量:4                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:2                        结贴的总分数:40                       
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:2                        未结的总分数:120                      
    结贴的百分比:50.00 %               结分的百分比:25.00 %                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    楼主加油
      

  2.   

    验证成功后jButton.addActionListener(new java.awt.event.ActionListener(){
    public void actionPerformed(java.awt.event.ActionEvent e) {
    // 这里面验证成功后+个dispose就可以了
    }}
    );