Java实现酒店客房管理系统

时间:2022-06-03 09:58:14

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

loginframe.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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实现酒店客房管理系统

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。