飞奔的炮台 发表于 2021-9-18 18:05:03

Java实现酒店客房管理系统

这篇文章主要为大家详细介绍了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实现酒店客房管理系统
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持CodeAE代码之家。

http://www.zzvips.com/article/176847.html
页: [1]
查看完整版本: Java实现酒店客房管理系统