package booksys.presentation ;
import booksys.application.domain.* ;
import java.awt.* ;
import java.awt.event.* ;
import java.sql.Date ;
import java.sql.Time ;
import java.util.* ;
public class StaffUI
extends Canvas
implements BookingObserver
{
final static int LEFT_MARGIN = 50 ;
final static int TOP_MARGIN = 50 ;
final static int BOTTOM_MARGIN = 50 ;
final static int ROW_HEIGHT = 30 ;
final static int COL_WIDTH = 60 ;
final static int PPM = 2 ; // Pixels per minute
final static int PPH = 60 * PPM ; // Pixels per hours
final static int TZERO = 18 ; // Earliest time shown
final static int SLOTS = 12 ; // Number of booking slots shown
// Routines to convert between (x, y) and (time, table),为的是确定一个“预定”项的显示位置
private int timeToX(Time time) {
return LEFT_MARGIN
+ PPH * (time.getHours() - TZERO)
+ PPM * time.getMinutes() ;
}
private Time xToTime(int x) {
x -= LEFT_MARGIN ;
int h = (x / PPH) + TZERO ;
int m = (x % PPH) / PPM ;
return new Time(h, m, 0) ;
}
private int tableToY(int table) {
return TOP_MARGIN + (ROW_HEIGHT * (table - 1)) ;
}
private int yToTable(int y) {
return ((y - TOP_MARGIN) / ROW_HEIGHT) + 1 ;
}
// Data members
private Frame parentFrame ; //用户界面的容器
private BookingSystem bs ; //包含对一个BookingSystem对象的引用
private Image offscreen ;
private Vector tableNumbers ; //包含该餐馆的所有桌面
private int firstX, firstY, currentX, currentY ;
private boolean mouseDown ;
public StaffUI(Frame f)
{
parentFrame = f ;
//update() ;2006.7.25
tableNumbers = BookingSystem.getTableNumbers() ;
setSize(LEFT_MARGIN + (SLOTS * COL_WIDTH),
TOP_MARGIN + tableNumbers.size()*ROW_HEIGHT + BOTTOM_MARGIN) ;//设置界面的大小
setBackground(Color.white) ;
bs = BookingSystem.getInstance() ; //创建一个BookingSystem对象
bs.addObserver(this) ; //告诉这一BookingSystem对象“谁”在关注它
Calendar now = Calendar.getInstance() ;
bs.display(new Date(now.getTimeInMillis())) ; //显示在当天被预定的桌子
//用鼠标选择一个预定项
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
currentX = firstX = e.getX() ;
currentY = firstY = e.getY() ;
if (e.getButton() == MouseEvent.BUTTON1) {
mouseDown = true ;
bs.selectBooking(yToTable(firstY), xToTime(firstX)) ;
}
}
});
addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
mouseDown = false ;
bs.transfer(xToTime(currentX), yToTable(currentY)) ; //确定被选定项的预定时间和桌面
}
});
//侦听鼠标被拖动时,鼠标的坐标,并更新它!
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
currentX = e.getX() ;
currentY = e.getY() ;
update() ;
}
}) ;
}
public void update()
{
repaint() ;
}
public void paint(Graphics g)
{
update(g) ;
}
public void update(Graphics g)
{
Dimension canvasSize = getSize() ;
if (offscreen == null) {
offscreen = this.createImage(canvasSize.width, canvasSize.height) ;
}
Graphics og = offscreen.getGraphics() ;
og.setColor(getBackground()) ;
og.fillRect(0, 0, canvasSize.width, canvasSize.height) ;
og.setColor(Color.black) ;
// Draw screen outlines
og.drawLine(LEFT_MARGIN, 0, LEFT_MARGIN, canvasSize.height) ;
og.drawLine(0, TOP_MARGIN, canvasSize.width, TOP_MARGIN) ;
// Write table numbers and horizontal rules
for (int i = 0; i < tableNumbers.size(); i++) {
int y = TOP_MARGIN + (i+1)*ROW_HEIGHT ;
og.drawString(Integer.toString(i+1), 0, y) ;
og.drawLine(LEFT_MARGIN, y, canvasSize.width, y) ;
}
// Write time labels and vertical rules
for (int i = 0; i < SLOTS; i++) {
String tmp = (TZERO+(i/2)) + (i%2 == 0? ":00" : ":30") ;
int x = LEFT_MARGIN + i*COL_WIDTH ;
og.drawString(tmp, x, 40) ;
og.drawLine(x, TOP_MARGIN, x, canvasSize.height-BOTTOM_MARGIN) ;
}
// Display booking information
/* og.drawString(((java.util.Date) bs.getCurrentDate()).toString(),
LEFT_MARGIN, 20) ;
Enumeration enum = bs.getBookings() ;
while (enum.hasMoreElements()) {
Booking b = (Booking) enum.nextElement() ;
int x = timeToX(b.getTime()) ;
int y = tableToY(b.getTable().getNumber()) ;
og.setColor(Color.gray) ;
og.fillRect(x, y, 4*COL_WIDTH, ROW_HEIGHT) ;
if (b == bs.getSelectedBooking()) {
og.setColor(Color.red) ;
og.drawRect(x, y, 4*COL_WIDTH, ROW_HEIGHT) ;
}
og.setColor(Color.white) ;
og.drawString(b.getDetails(), x, y + ROW_HEIGHT/2) ;
}
// Draw an outline to represent position of dragged booking
Booking b = bs.getSelectedBooking() ;
if (mouseDown && b != null) {
int x = timeToX(b.getTime()) + currentX - firstX ;
int y = tableToY(b.getTable().getNumber()) + currentY - firstY ;
og.setColor(Color.red) ;
og.drawRect(x, y, 4*COL_WIDTH, ROW_HEIGHT) ;
}
// Write to canvas
*/
g.drawImage(offscreen, 0, 0, this) ;
}
public boolean message(String message, boolean confirm)
{
ConfirmDialog d =
new ConfirmDialog(parentFrame, message, confirm) ;
d.show() ;
return d.isConfirmed() ;
}
void displayDate()
{
DateDialog d
= new DateDialog(parentFrame, "Enter a date") ;
d.show() ;
if (d.isConfirmed()) {
Date date = d.getDate() ;
bs.display(date) ;
}
}
void addReservation()
{
ReservationDialog d
= new ReservationDialog(parentFrame,
"Enter reservation details") ;
d.show() ;
if (d.isConfirmed()) {
bs.makeReservation(d.getCovers(),
bs.getCurrentDate(),
d.getTime(),
d.getTableNumber(),
d.getCustomerName(),
d.getPhoneNumber()) ;
}
}
void addWalkIn()
{
WalkInDialog d
= new WalkInDialog(parentFrame,
"Enter walk-in details") ;
d.show() ;
if (d.isConfirmed()) {
bs.makeWalkIn(d.getCovers(),
bs.getCurrentDate(),
d.getTime(),
d.getTableNumber()) ;
}
}
void cancel()
{
bs.cancel() ;
}
void recordArrival()
{
Calendar now = Calendar.getInstance() ;
bs.recordArrival(new Time(now.getTimeInMillis())) ;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Java餐馆订单服务系统源代码
共75个文件
class:45个
java:26个
properties:1个
4星 · 超过85%的资源 需积分: 10 94 下载量 81 浏览量
2008-08-30
11:42:50
上传
评论 6
收藏 68KB RAR 举报
温馨提示
这一实验性的“餐馆系统”是一个很典型商业应用,但并不复杂。归根结底,就实现5个功能:1)增加一个新的预约(涉及数据库中的一个insert操作),2)删除一个被选中的预约(delete操作),3)在一个已有预约上记录到达时间(提前预约的顾客来吃饭了)(对应update操作),4)更改分配给一个预约的餐桌(update操作),5)显示指定日期内所有已有的预约(select操作)。从数据库的角度来看,要实现这些功能不难。在我们的样板系统中,在运行时主要通过以下对象的合作,实现上述功能。
资源推荐
资源详情
资源评论
收起资源包目录
booksys080522.rar (75个子文件)
booksys080522
.project 389B
booksys.mdb 184KB
bin
booksys
presentation
BookingDialog.class 3KB
BookingSystemApp$3.class 895B
BookingSystemApp$5.class 887B
StaffUI$1.class 1KB
ConfirmDialog$2.class 773B
StaffUI.class 7KB
WalkInDialog.class 1KB
StaffUI$3.class 856B
DateDialog$1.class 690B
BookingSystemApp$6.class 894B
DateDialog$3.class 755B
ReservationDialog.class 2KB
StaffUI$2.class 1KB
DateDialog$2.class 755B
ConfirmDialog$3.class 773B
BookingSystemApp.class 3KB
BookingDialog$3.class 773B
ConfirmDialog$1.class 746B
BookingSystemApp$2.class 892B
ConfirmDialog.class 2KB
BookingDialog$2.class 773B
BookingDialog$1.class 746B
BookingSystemApp$1.class 810B
BookingSystemApp$4.class 890B
BookingSystemApp$7.class 783B
DateDialog.class 2KB
application
persistency
PersistentTable.class 522B
PersistentReservation.class 1017B
PersistentCustomer.class 623B
TableMapper.class 4KB
BookingMapper.class 6KB
PersistentBooking.class 211B
PersistentWalkIn.class 816B
CustomerMapper.class 4KB
domain
Customer.class 645B
Table.class 562B
BookingSystem.class 4KB
BookingImp.class 2KB
Reservation.class 2KB
WalkIn.class 874B
Booking.class 586B
BookingObserver.class 204B
Restaurant.class 3KB
storage
Database.class 2KB
Connectivity.class 1KB
src
booksys
presentation
BookingSystemApp.java 3KB
StaffUI.java 6KB
WalkInDialog.java 717B
ReservationDialog.java 1KB
ConfirmDialog.java 1KB
DateDialog.java 1KB
BookingDialog.java 2KB
application
persistency
PersistentBooking.java 147B
PersistentReservation.java 500B
PersistentWalkIn.java 431B
PersistentTable.java 267B
CustomerMapper.java 3KB
TableMapper.java 3KB
BookingMapper.java 4KB
PersistentCustomer.java 284B
domain
Reservation.java 1KB
BookingObserver.java 156B
WalkIn.java 289B
Table.java 290B
BookingImp.java 1KB
Booking.java 731B
Restaurant.java 1KB
BookingSystem.java 5KB
Customer.java 324B
storage
Connectivity.java 1KB
Database.java 1KB
booksys.properties 71B
.classpath 232B
共 75 条
- 1
hyz756
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页