注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

梦心语

精华荟萃,共同分享,广交博友

 
 
 

日志

 
 

2017年03月01日  

2017-03-01 23:34:36|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
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);
}
  评论这张
 
阅读(24)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017