
正文
客房预订界面代码java,酒店预订系统代码
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何用java编写比较完善的宾馆管理系统
package room;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.njit.HelloHotel;
import com.wind.util.DbUtil;
import java.io.UnsupportedEncodingException;
import java.sql.*;
public class roomadd extends JFrame
{
private JTextField roomno,roomcost,roomstatus,roomtype;
//private JComboBox roomtype;
private JButton ok,cancel,return1,chakan;
private Container contain;
public roomadd()
{
super();
this.setSize(350,450);
this.setTitle("添加信息");
this.setLocationRelativeTo(getOwner()); //居中
//设置组件布局
Container contain=getContentPane();
contain.setLayout(new BoxLayout(contain,BoxLayout.Y_AXIS));
//添加组件
JPanel cont=new JPanel (new GridLayout(4,2));
//添加组件
/*cont.add(new JLabel("客房类型"));
roomtype=new JComboBox();
roomtype.addItem("单人间");
roomtype.addItem("双人间");
roomtype.addItem("三人房");
roomtype.addItem("四人间");
cont.add(roomtype);*/
cont.add(new JLabel("客房号"));
roomno=new JTextField(10);
cont.add(roomno);
cont.add(new JLabel("房间类型"));
roomtype=new JTextField(10);
cont.add(roomtype);
cont.add(new JLabel("客房价格"));
roomcost=new JTextField(10);
cont.add(roomcost);
cont.add(new JLabel("客房状态"));
roomstatus=new JTextField(10);
cont.add(roomstatus);
//按钮
JPanel cont1=new JPanel(new FlowLayout());
ok=new JButton("添加");
cancel=new JButton("取消");
chakan=new JButton("查看");
return1=new JButton("返回");
cont1.add(ok);
cont1.add(cancel);
cont1.add(chakan);
cont1.add(return1);
contain.add(cont);
contain.add(cont1);
//注册监听器
ok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
//ok事件处理
DbUtil util = new DbUtil();
Connection con=null;
try {
con = (Connection) util.getCon();
} catch (Exception e2) {
e2.printStackTrace();
}
String sql="insert into room values(?,?,?,?)";
PreparedStatement pstmt = null;
try {
pstmt = (PreparedStatement)con.prepareStatement(sql);
} catch (SQLException e2) {
e2.printStackTrace();
}
try {
pstmt.setString(1,roomno.getText());
pstmt.setString(2,roomtype.getText());
pstmt.setString(3,roomcost.getText());
pstmt.setString(4,roomstatus.getText());
pstmt.executeUpdate();
} catch (SQLException e1) {
e1.printStackTrace();
}
JOptionPane.showMessageDialog(null, " 注册成功!");
}
});
//查看添加的预订信息
chakan.addActionListener(new ActionListener(){
private JTable table;
public void actionPerformed(ActionEvent e) {
if(e.getSource()==chakan){
Connection con = null;
ResultSet rs=null;
DbUtil util = new DbUtil();
String[][] a;
String[] name = { "", "", "", ""};
int row = 0;
try {
con = (Connection) util.getCon();
}
catch (Exception e1) {
e1.printStackTrace();
}
try {
String roomno = null;
rs=(ResultSet) util.sroom(con, roomno);
} catch (Exception e1) {
e1.printStackTrace();
}
try {
while(rs.next()){
row++;
}
a = new String[row + 1][4];
a[0][0] = " 客房号";
a[0][1] = " 客房类型";
a[0][2] = " 客房价格 ";
a[0][3] = " 客房状态";
table = new JTable(a,name);
int i = 0;
String roomno = null;
rs=(ResultSet)util.sroom(con,roomno);
while (rs.next()) {
// 往表中填充查询到的数据
i++;
int j = 0;
table.setValueAt(new String(rs.getString("roomno").getBytes("ISO-8859-1"),"GBK") + "", i, j);
table.setValueAt(new String(rs.getString("roomtype").getBytes("ISO-8859-1"),"GBK") + "", i, ++j);
table.setValueAt(new String(rs.getString("roomcost").getBytes("ISO-8859-1"),"GBK") + "", i, ++j);
table.setValueAt(new String(rs.getString("roomstatus").getBytes("ISO-8859-1"),"GBK") + "", i, ++j);
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
JFrame b5=new JFrame("顾客预订信息");
b5.setLayout(new BorderLayout());
b5.add(table);
b5.setBounds(200, 200, 500, 300);
b5.setVisible(true);
b5.setResizable(true);
b5.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
});
cancel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
return1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
HelloHotel hello=new HelloHotel();
hello.setVisible(true);
dispose();
}
});
pack();
}
public static void main(String[] args) {
roomadd w=new roomadd();
w.setVisible(true);
}
}
大概改改就可以是你的需要的了
相关问答
Q1: 求用Java写的网上订房程序 要有酒店类 房间类 客户类 订房记录类 模拟一个人订房操作
酒店类
package fdsa;
public class Hotel {
private String hotelID;
private String hotelName;
private String hoteladdess;
public String getHotelID() {
return hotelID;
}
public void setHotelID(String hotelID) {
this.hotelID = hotelID;
}
public String getHotelName() {
return hotelName;
}
public void setHotelName(String hotelName) {
this.hotelName = hotelName;
}
public String getHoteladdess() {
return hoteladdess;
}
public void setHoteladdess(String hoteladdess) {
this.hoteladdess = hoteladdess;
}
public String getHotelPhone() {
return hotelPhone;
}
public void setHotelPhone(String hotelPhone) {
this.hotelPhone = hotelPhone;
}
private String hotelPhone;
}
客户类
public class Client{
private String clientName;
private String clientID;
public String getClientName() {
return clientName;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
public String getClientID() {
return clientID;
}
public void setClientID(String clientID) {
this.clientID = clientID;
}
}
房间类
public class Room{
private String roomID;
private Hotel hotelID;
public String getRoomID() {
return roomID;
}
public void setRoomID(String roomID) {
this.roomID = roomID;
}
public Hotel getHotelID() {
return hotelID;
}
public void setHotelID(Hotel hotelID) {
this.hotelID = hotelID;
}
public String getRoomAmount() {
return roomAmount;
}
public void setRoomAmount(String roomAmount) {
this.roomAmount = roomAmount;
}
private String roomAmount;
}
Q2: java面试题:酒店预订!
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("是否是会员?y/n");
String H = input.next();
System.out.println("请输入入住日期:");
System.out.println("例如2009-03-16");
String in = input.next();
System.out.println("请输离开日期:");
System.out.println("例如2009-03-16");
String out = input.next();
//String in = s.substring(5,15);
//String out = s.substring(15,26);
//System.out.println(in+" "+out);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
try {
c1.setTime(sdf.parse(in));
c2.setTime(sdf.parse(out));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long time1 = c1.getTimeInMillis();
long time2 = c2.getTimeInMillis();
long tian = (time2-time1)/(1000*24*3600);
long tian1 = tian;
System.out.println("tian "+tian);
int week1 = c1.get(Calendar.DAY_OF_WEEK)-1;
//System.out.println(week1);
//int week2 = c2.get(Calendar.DAY_OF_WEEK)-1;
//System.out.println(week2);
int count = 0;
while(tian10){
if(week1 == 6 || week1==0){
count++;
}
if(week1==6){
week1 = 0;
week1--;
}
tian1--;
week1++;
}
System.out.println("count "+count);
long rujia;
long qitian;
long hanting;
if(H.equals("y")){
rujia = (tian-count)*80+count*80;
System.out.println("tian "+tian);
qitian = (tian-count)*110+count*50;
hanting = (tian-count)*100+count*40;
}else{
rujia = (tian-count)*110+count*90;
qitian = (tian-count)*160+count*60;
hanting = (tian-count)*220+count*150;
}
System.out.println("tian " + tian);
System.out.println("rujia "+rujia);
System.out.println("hanting "+hanting);
System.out.println("qitian "+qitian);
if(rujiaqitian rujiahanting){
System.out.println("如家");
}else if(qitianrujia qitianhanting){
System.out.println("七天");
}else if(hantingrujia hantingqitian){
System.out.println("汉庭");
}else if(hanting==rujia || hanting==qitian){
System.out.println("汉庭");
}else if(qitian==rujia qitianhanting){
System.out.println("七天");
}
}
我没怎么测试 自己测测吧 还有一些约束用户输入啥的 严谨性什么的








