栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java实现酒店客房管理系统

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java实现酒店客房管理系统

本文实例为大家分享了Java实现酒店客房管理系统的具体代码,供大家参考,具体内容如下

Loginframe.java

package loginManage;

import java.awt.Color;
import java.awt.EventQueue;
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.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.ResultSet;
import com.swtdesigner.SwingResourceManager;

import db.JDBC;
public class Loginframe {

 private JLabel label;
 private JButton button;
 private JButton btnregister;
 private JButton btnreset;
 private JButton btnlogin;
 private JLabel labpwd;
 private JLabel labUserName;
 private JPasswordField textpwd;
 private JTextField textUsername;
 public Jframe frame;

 
 public static void main(String args[]) {
 EventQueue.invokeLater(new Runnable() {
  public void run() {
  try {
   Loginframe window = new Loginframe();
   
   window.frame.setVisible(true);
  } catch (Exception e) {
   e.printStackTrace();
  }
  }
 });
 }

 
 public Loginframe() {
 createContents();
 }

 
 private void createContents() {
 frame = new Jframe();
 frame.setTitle("登录");
 frame.getContentPane().setFocusCycleRoot(true);
 frame.getContentPane().setBackground(Color.LIGHT_GRAY);
 frame.getContentPane().setLayout(null);
 frame.setBounds(400, 150, 490, 375);
 frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);

 btnlogin = new JButton();
 btnlogin.addActionListener(new ActionListener() {
  public void actionPerformed(final ActionEvent arg0) {
  String name = textUsername.getText().trim();
  String password = textpwd.getText().trim();
  Connection conn = null;
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  int flag=0;
  if(name.equals("")||password.equals("")){
   flag=2;
  }
  int right=0;
  try {
   String sql = "select * from login where userName=?";
    conn = (Connection)JDBC.getConnection();
    pstmt= (PreparedStatement)conn.prepareStatement(sql);
    pstmt.setString(1, name);
    rs=(ResultSet) pstmt.executeQuery();
    while(rs.next()){
     String userName=rs.getString("userName");
     String passWord=rs.getString("passWord");
     right=rs.getInt("admin");
     if(userName.equals(name)&&passWord.equals(password)){
     flag = 1;
     }
    }
    switch(flag){
     case 1:
     if((right==1)){
BackRun admin = new BackRun();
admin.frame.setVisible(true);
frame.setVisible(false);
break;
      }else{
FrontRun admin= new FrontRun();
admin.frame.setVisible(true);
frame.setVisible(false);
break;
     }
     case 2:
    JOptionPane.showMessageDialog(btnlogin ,"用户名或密码不能为空,请您重新输入!");
break;
     default: 
JOptionPane.showMessageDialog(btnlogin ,"用户名或密码 不正确,请您重新输入!");
break;

     }
     
     
     
    } catch (Exception e) {
   e.printStackTrace();
   }
    
   
   
  
  }
 });
 
  
  
 btnlogin.setText(" 登陆");
 btnlogin.setBounds(75, 215, 83, 28);
 frame.getContentPane().add(btnlogin);

 btnreset = new JButton();
 btnreset.addActionListener(new ActionListener() {
  public void actionPerformed(final ActionEvent arg0) {
  textUsername.setText("");
  textpwd.setText("");
  
  }
 });
 btnreset.setText("重置");
 btnreset.setBounds(195, 215, 83, 28);
 frame.getContentPane().add(btnreset);

 labUserName = new JLabel();
 labUserName.setText("用户名:");
 labUserName.setBounds(75, 130, 52, 18);
 frame.getContentPane().add(labUserName);

 labpwd = new JLabel();
 labpwd.setText("密  码:");
 labpwd.setBounds(75, 175, 66, 18);
 frame.getContentPane().add(labpwd);

 textUsername = new JTextField();
 textUsername.setBounds(145, 130, 188, 22);
 frame.getContentPane().add(textUsername);

 textpwd = new JPasswordField();
 textpwd.setBounds(145, 170, 188, 22);
 frame.getContentPane().add(textpwd);

 btnregister = new JButton();
 btnregister.addActionListener(new ActionListener() {
  public void actionPerformed(final ActionEvent arg0) {
  Register rs = new Register();
  rs.frame.setVisible(true);
  }
 });
 btnregister.setText("注册");
 btnregister.setBounds(270, 270, 81, 28);
 frame.getContentPane().add(btnregister);

 button = new JButton();
 button.addActionListener(new ActionListener() {
  public void actionPerformed(final ActionEvent arg0) {
  System.exit(0);
  }
 });
 button.setText("退出");
 button.setBounds(310, 215, 83, 28);
 frame.getContentPane().add(button);

 label = new JLabel();
 label.setText("还没有账号?赶快点击注册吧!");
 label.setBounds(85, 275, 181, 33);
 frame.getContentPane().add(label);

} 
}

Register.java

package loginManage;

import java.awt.Color;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.mysql.jdbc.PreparedStatement;
import com.swtdesigner.SwingResourceManager;
public class Register {
 private JButton button;
 private JButton btnregister;
 private JLabel labpwd;
 private JLabel labUserName;
 private JPasswordField textpwd;
 private JTextField textUsername;
 public Jframe frame;
  public boolean flag=false; 
 
 public static void main(String args[]) {
 EventQueue.invokeLater(new Runnable() {
  public void run() {
  try {
   Register window = new Register();
   
   window.frame.setVisible(true);
  } catch (Exception e) {
   e.printStackTrace();
  }
  }
 });
 }

 
 public Register() {
 createContents();
 }

 
 private void createContents() {
 
 
 frame = new Jframe();
 frame.getContentPane().setFocusCycleRoot(true);
 frame.getContentPane().setBackground(Color.LIGHT_GRAY);
 frame.getContentPane().setLayout(null);
 frame.setBounds(350, 150, 500, 375);
 frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);

 labUserName = new JLabel();
 labUserName.setText("用户名:");
 labUserName.setBounds(109, 182, 52, 18);
 frame.getContentPane().add(labUserName);

 labpwd = new JLabel();
 labpwd.setText("密  码:");
 labpwd.setBounds(109, 224, 66, 18);
 frame.getContentPane().add(labpwd);

 textUsername = new JTextField();
 textUsername.setBounds(190, 180, 188, 22);
 frame.getContentPane().add(textUsername);

 textpwd = new JPasswordField();
 textpwd.setBounds(190, 222, 188, 22);
 frame.getContentPane().add(textpwd);

 btnregister = new JButton();
 btnregister.addActionListener(new ActionListener() {
  @SuppressWarnings("deprecation")
  public void actionPerformed(final ActionEvent arg0) {

  PreparedStatement st=null;
  Connection con =null;
  String sqlStr="insert into login(userName,passWord) values(?,?)";
  try {
   Class.forName("com.mysql.jdbc.Driver");
  } catch (ClassNotFoundException e1) {
   e1.printStackTrace();
  }
  try {
   con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hotel","root","125800");
   st = (PreparedStatement) con.prepareStatement(sqlStr);

  } catch (SQLException e1) {
   e1.printStackTrace();
  }
  
  String name = textUsername.getText().trim();
  String password = textpwd.getText().trim(); 
  if(name.equals("")||password.equals("")){
   JOptionPane.showMessageDialog(btnregister ,"用户名或密码不能为空,请您重新输入!");

  }else{
  try {
   st.setString(1,name);
   st.setString(2,password);
   st.execute();
   flag=true;
   if(flag){
   JOptionPane.showMessageDialog(btnregister, "注册成功n点确定返回登录界面");
   Loginframe backMain=new Loginframe();
   backMain.frame.setVisible(true);
   frame.setVisible(false);
   }else{
   JOptionPane.showMessageDialog(btnregister, "注册失败n点确定返回登录界面");
   }
  } catch (SQLException e) {
   e.printStackTrace();
  }
  }
//   JOptionPane.showMessageDialog(btnregister, "注册成功n点确定返回登录界面");
//   loginframe backMain=new loginframe();
//   backMain.frame.setVisible(true);
//   frame.setVisible(false);

    try {
   st.close();
   con.close();

  } catch (SQLException e1) {
   e1.printStackTrace();
  }
     

  }
 });
 btnregister.setText("提交");
 btnregister.setBounds(162, 268, 95, 28);
 frame.getContentPane().add(btnregister);

 button = new JButton();
 button.addActionListener(new ActionListener() {
  public void actionPerformed(final ActionEvent arg0) {
    frame.setVisible(false);

  }
 });
 button.setText("返回");
 button.setBounds(283, 268, 95, 28);
 frame.getContentPane().add(button);

 final JLabel label = new JLabel();
 label.setIcon(SwingResourceManager.getIcon(Register.class, "/648.gif"));
 label.setBounds(0, 0, 492, 341);
 frame.getContentPane().add(label);
// frame.getContentPane().setFocusTraversalPolicy(new FocusTraversalonArray(new Component[] {labUserName, labpwd, btnregister, textUsername, textpwd, button}));

 }


}

完整代码:Java实现酒店客房管理系统

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/138953.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号