开发工具:
文件大小: 3mb
下载次数: 0
上传时间: 2009-12-24
详细说明: 手工写的旅店管理系统界面。 import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.io.FileOutputStream; import java.io.ObjectOutputStream; import java.util.HashMap; import java.util.Iterator; import java.util.Set; import javax.swing.ButtonGroup; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import jav ax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JRadioButton; import javax.swing.JTextField; public class MyButton extends JButton implements MouseListener, ActionListener { private static final long serialVersionUID = 6261021704484837560L; private JPopupMenu popMenu; private ButtonGroup bg; private JRadioButton SetDark;// 置为脏房,待打扫 private JRadioButton SetClean;// 置为应该打扫的房间 private JRadioButton SetUsing;// 置为正在使用的房间 private JRadioButton SetHouseNum;// 设置房号 private JRadioButton SetEmpty;//置为空房 private JRadioButton Delete;//删除 private JRadioButton Bujiaoyajin;//补交押金 private String HouseAr, HouseNu; private Color Housecolor; private int ID; private double SingelSal; public double getSingelSal() { return SingelSal; } public void setSingelSal(double singelSal) { SingelSal = singelSal; } private HashMap tempMap; private Customer customer; public MyButton(int ID,HashMap tempMap) { super.setIcon(new ImageIcon("Blue Victorian.JPG")); this.ID = ID; this.tempMap = tempMap; init(); } public MyButton() { super.setIcon(new ImageIcon("Blue Victorian.JPG")); init(); } public void init() { Housecolor = Color.GREEN; super.setBackground(Housecolor); popMenu = new JPopupMenu(); bg = new ButtonGroup(); SetDark = new JRadioButton("置为脏房"); SetClean = new JRadioButton("置为闲置房"); SetUsing = new JRadioButton("添加留客"); SetHouseNum = new JRadioButton("初始房态"); SetEmpty = new JRadioButton("置为空房"); Delete = new JRadioButton("删除本房"); Bujiaoyajin = new JRadioButton("补交押金"); // 添加action监听 SetDark.addActionListener(this); SetClean.addActionListener(this); SetUsing.addActionListener(this); SetHouseNum.addActionListener(this); SetEmpty.addActionListener(this); Delete.addActionListener(this); Bujiaoyajin.addActionListener(this); // 加入buttongroup,实现单选 bg.add(SetClean); bg.add(SetDark); bg.add(SetUsing); bg.add(SetHouseNum); bg.add(SetEmpty); bg.add(Delete); bg.add(Bujiaoyajin); //bg.add(Delete); // 设置相应房态颜色 popMenu.add(SetDark); popMenu.add(SetClean); popMenu.add(SetUsing); popMenu.add(SetHouseNum); popMenu.add(SetEmpty); popMenu.add(Bujiaoyajin); //popMenu.add(Delete); // 设置jbutton的固定大小 setMaximumSize(new Dimension(80, 60)); setMinimumSize(new Dimension(80, 60)); setPreferredSize(new Dimension(80, 60)); this.addMouseListener(this); } public void mouseClicked(MouseEvent arg0) {} public void mouseEntered(MouseEvent arg0) {} public void mouseExited(MouseEvent arg0) {} public void mouseReleased(MouseEvent arg0) {} // 为jbuuton添加popmenu public void mousePressed(MouseEvent arg0) { if (arg0.getButton() == MouseEvent.BUTTON3) { popMenu.show(arg0.getComponent(), arg0.getX(), arg0.getY()); } } //定位该button在map中的位置 public MyButton indexof() { MyButton b = null; Set set = this.tempMap.keySet(); Iterator iter = set.iterator(); while(iter.hasNext()) { String id = iter.next(); if(this.ID == Integer.parseInt(id.trim())) b = this.tempMap.get(id); } return b; } //getcustomer的信息 public Customer getCustomer() { return this.customer; } // 为选项添加监听 public void actionPerformed(ActionEvent e) { if(e.getSource() == Bujiaoyajin) { System.out.println("fgfhjhk"); } if (e.getSource() == SetDark) { Housecolor = Color.yellow; this.setBackground(Housecolor); indexof().setHouseColor(Housecolor); Write(); } if (e.getSource() == SetClean) { Housecolor = Color.gray; this.setBackground(Housecolor); indexof().setHouseColor(Housecolor); Write(); } if (e.getSource() == Delete) { tempMap.remove(ID); Write(); } if (e.getSource() == SetEmpty) { Housecolor = Color.green; this.setBackground(Housecolor); indexof().setHouseColor(Housecolor); Write(); } if (e.getSource() == SetUsing) { new GetCustomerInfo(); this.setBackground(Housecolor); } if (e.getSource() == SetHouseNum) { new GetHouseInfo(); } } public int getID() { return ID; } public void setID(int id) { ID = id; } //保存到本地 public void Write() { try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("d:/ButtonsInfo.shf")); oos.writeObject(this.tempMap); oos.flush(); oos.close(); } catch (Exception e) { e.printStackTrace(); } } //为外层程序提供 public void setHouseAr(String str) { this.HouseAr = str; } public String getHouseAr() { return this.HouseAr; } public void setHouseNu(String str) { this.HouseNu = str; } public String getHouseNu() { return this.HouseNu; } public void setHouseColor(Color cl) { this.Housecolor = cl; } public Color getHouseColor() { return this.Housecolor; } // 设置房号的窗口 class GetHouseInfo extends JFrame implements ActionListener { private static final long serialVersionUID = 4824740927444846504L; private JPanel p, p1, p2, p3,p4; private JLabel HouseArea, HouseNum,SingleSal; private JTextField HouseA, HouseN,SinglS; private JButton Entrue, Cansal; private String A,N; public GetHouseInfo() { super.setTitle("初始房态"); p = new JPanel(); p1 = new JPanel(); p2 = new JPanel(); p3 = new JPanel(); p4 = new JPanel(); HouseArea = new JLabel("设定房区:"); HouseNum = new JLabel("设定房号:"); SingleSal = new JLabel("设定单价:"); HouseA = new JTextField(10); HouseN = new JTextField(10); SinglS = new JTextField(10); Entrue = new JButton("确定"); Cansal = new JButton("取消"); Entrue.addActionListener(this); Cansal.addActionListener(this); p.setLayout(new GridLayout(4, 1)); p1.add(HouseArea); p1.add(HouseA); p2.add(HouseNum); p2.add(HouseN); p3.add(Entrue); p3.add(Cansal); p4.add(SingleSal); p4.add(SinglS); p.add(p1); p.add(p2); p.add(p4); p.add(p3); this.add(p); this.setLocation(450, 300); this.setAlwaysOnTop(true); this.setVisible(true); this.pack(); } public String getHouseA() { return this.A; } public String getHouseN() { return this.N; } @SuppressWarnings("deprecation") public void actionPerformed(ActionEvent arg0) { if (arg0.getSource() == Entrue) { A = HouseAr = HouseA.getText(); N = HouseNu = HouseN.getText(); SingelSal = new Double(SinglS.getText().trim()).doubleValue(); MyButton.this.setText(HouseAr + "\n" + HouseNu); indexof().setHouseNu(A+N); Write(); this.hide(); } if (arg0.getSource() == Cansal) { this.hide(); } } } //留客信息录入 class GetCustomerInfo extends JFrame implements ActionListener { private static final long serialVersionUID = 4824740927444846504L; private JPanel p, p1, p2, p3,p4,p5,p6; private JLabel Name, SumCash,SumDays,Sex,TelePhone; private JTextField HouseA, HouseN,SumD,telePhone; private JButton Entrue, Cansal; private JLabel sex; private ButtonGroup bg; private JRadioButton man,waman; private String sexStr; public GetCustomerInfo() { super.setTitle("录入顾客信息"); p = new JPanel(); p1 = new JPanel(); p2 = new JPanel(); p3 = new JPanel(); p4 = new JPanel(); p5 = new JPanel(); p6 = new JPanel(); Name = new JLabel("旅客姓名:"); sex = new JLabel("性别: "); TelePhone = new JLabel("联系方式:"); SumCash = new JLabel("旅客押金:"); SumDays = new JLabel("留住天数:"); HouseA = new JTextField(10); telePhone = new JTextField(10); HouseN = new JTextField(10); SumD = new JTextField(10); Entrue = new JButton("确定"); Cansal = new JButton("取消"); bg = new ButtonGroup(); man = new JRadioButton("男"); waman = new JRadioButton("女"); bg.add(man); bg.add(waman); p6.add(sex); p6.add(man); p6.add(waman); Entrue.addActionListener(this); Cansal.addActionListener(this); man.addActionListener(this); waman.addActionListener(this); p.setLayout(new GridLayout(6, 1)); p1.add(Name); p1.add(HouseA); p2.add(SumCash); p2.add(HouseN); p3.add(Entrue); p3.add(Cansal); p4.add(SumDays); p4.add(SumD); p5.add(TelePhone); p5.add(telePhone); p.add(p1); p.add(p5); p.add(p6); p.add(p2); p.add(p4); p.add(p3); this.add(p); this.setLocation(450, 300); this.setVisible(true); this.pack(); } @SuppressWarnings("deprecation") public void actionPerformed(ActionEvent arg0) { if(arg0.getSource() == man) { sexStr = "男"; } if(arg0.getSource() == waman) { sexStr = "女"; } if (arg0.getSource() == Entrue) { customer = new Customer(HouseA.getText(),sexStr,telePhone.getText(), new Integer(SumD.getText().trim()).intValue(), new Integer(HouseN.getText().trim()).intValue()); Housecolor = Color.blue; MyButton.this.setBackground(Housecolor); indexof().setHouseColor(Housecolor); if(new Double(HouseN.getText().trim()).doubleValue() < SingelSal) { JOptionPane.showMessageDialog(null, "押金不足!"); } else { Write(); this.hide(); } } if (arg0.getSource() == Cansal) { this.hide(); } } } public static void main(String[] s) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); MyButton mb = new MyButton(); panel.add(mb); frame.add(panel); frame.setSize(600, 600); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.