Java實(shí)現(xiàn)酒店客房管理系統(tǒng)
本文實(shí)例為大家分享了Java實(shí)現(xiàn)酒店客房管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
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 ,"用戶名或密碼不能為空,請(qǐng)您重新輸入!");
break;
default:
JOptionPane.showMessageDialog(btnlogin ,"用戶名或密碼 不正確,請(qǐng)您重新輸入!");
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("注冊(cè)");
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("還沒(méi)有賬號(hào)?趕快點(diǎn)擊注冊(cè)吧!");
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 ,"用戶名或密碼不能為空,請(qǐng)您重新輸入!");
}else{
try {
st.setString(1,name);
st.setString(2,password);
st.execute();
flag=true;
if(flag){
JOptionPane.showMessageDialog(btnregister, "注冊(cè)成功\n點(diǎn)確定返回登錄界面");
LoginFrame backMain=new LoginFrame();
backMain.frame.setVisible(true);
frame.setVisible(false);
}else{
JOptionPane.showMessageDialog(btnregister, "注冊(cè)失敗\n點(diǎn)確定返回登錄界面");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
// JOptionPane.showMessageDialog(btnregister, "注冊(cè)成功\n點(diǎ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實(shí)現(xiàn)酒店客房管理系統(tǒng)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java代碼實(shí)現(xiàn)酒店管理系統(tǒng)
- Java實(shí)現(xiàn)簡(jiǎn)單酒店管理系統(tǒng)
- Java實(shí)戰(zhàn)之酒店人事管理系統(tǒng)的實(shí)現(xiàn)
- Java 實(shí)戰(zhàn)練手項(xiàng)目之酒店管理系統(tǒng)的實(shí)現(xiàn)流程
- 基于JavaSwing設(shè)計(jì)和實(shí)現(xiàn)的酒店管理系統(tǒng)
- Java實(shí)現(xiàn)簡(jiǎn)單的酒店管理系統(tǒng)
- java實(shí)現(xiàn)酒店管理系統(tǒng)
- Java swing實(shí)現(xiàn)酒店管理系統(tǒng)
- Java代碼實(shí)現(xiàn)簡(jiǎn)單酒店管理系統(tǒng)
相關(guān)文章
Java深度優(yōu)先遍歷解決排列組合問(wèn)題詳解
這篇文章主要介紹了Java深度優(yōu)先遍歷解決排列組合問(wèn)題詳解,深度優(yōu)先搜索是遞歸過(guò)程,帶有回退操作,因此需要使用棧存儲(chǔ)訪問(wèn)的路徑信息,當(dāng)訪問(wèn)到的當(dāng)前頂點(diǎn)沒(méi)有可以前進(jìn)的鄰接頂點(diǎn)時(shí),需要進(jìn)行出棧操作,將當(dāng)前位置回退至出棧元素位置,需要的朋友可以參考下2024-01-01
Spring Boot(二)之web綜合開(kāi)發(fā)
本篇文章為大家介紹spring boot的其它特性(有些未必是spring boot體系桟的功能,但是是spring特別推薦的一些開(kāi)源技術(shù)本文也會(huì)介紹),對(duì)了這里只是一個(gè)大概的介紹,特別詳細(xì)的使用我們會(huì)在其它的文章中來(lái)展開(kāi)說(shuō)明2017-05-05
關(guān)于Java創(chuàng)建線程的2種方式以及對(duì)比
這篇文章主要給大家介紹了關(guān)于Java創(chuàng)建線程的2種方式以及對(duì)比的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-01-01
java編程之基于SpringBoot框架實(shí)現(xiàn)掃碼登錄
本文將介紹基于SpringBoot + Vue + Android實(shí)現(xiàn)的掃碼登錄demo的總體思路,文中附含詳細(xì)示例代碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-09-09
JAVA中常用的數(shù)據(jù)結(jié)構(gòu)和XML使用解析
這篇文章主要介紹了JAVA中常用的數(shù)據(jù)結(jié)構(gòu)和XML使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-04-04

