📄 pizzastoreframe.java
字号:
toppingPane = new JPanel();
Border b7 = BorderFactory.createEtchedBorder();
Border b8 = BorderFactory.createTitledBorder(b7,"Topping");
toppingPane.setBorder(b8);
ButtonGroup group4 = new ButtonGroup();
PineappleB = new JRadioButton("Pineapple", true);
PineappleB.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setTopping(PineappleB.getActionCommand());
log.append(topping.getToppName() + "\n");
}
});
MushroomB = new JRadioButton("Mushroom", false);
MushroomB.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setTopping(MushroomB.getActionCommand());
log.append(topping.getToppName() + "\n");
}
});
GallicB = new JRadioButton("Gallic", false);
GallicB.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setTopping(GallicB.getActionCommand());
log.append(topping.getToppName() + "\n");
}
});
group4.add(PineappleB);
toppingPane.add(PineappleB);
group4.add(MushroomB);
toppingPane.add(MushroomB);
group4.add(GallicB);
toppingPane.add(GallicB);
//烤制时间选择
speedPane = new JPanel();
Border b9 = BorderFactory.createEtchedBorder();
Border b0 = BorderFactory.createTitledBorder(b9,"Speed");
speedPane.setBorder(b0);
ButtonGroup group5 = new ButtonGroup();
FastB = new JRadioButton("Fast", true);
FastB.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
getSpeed(FastB.getActionCommand());
log.append(speed.toString() + "\n");
}
});
NormalB = new JRadioButton("Normal", false);
NormalB.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
getSpeed(NormalB.getActionCommand());
log.append(speed.toString() + "\n");
}
});
SlowB = new JRadioButton("Slow", false);
SlowB.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
getSpeed(SlowB.getActionCommand());
log.append(speed.toString() + "\n");
}
});
group5.add(FastB);
speedPane.add(FastB);
group5.add(NormalB);
speedPane.add(NormalB);
group5.add(SlowB);
speedPane.add(SlowB);
//数量输入文本框
quantityPane = new JPanel();
Border b21 = BorderFactory.createEtchedBorder();
Border b22 = BorderFactory.createTitledBorder(b21,"Quantity");
quantityPane.setBorder(b22);
quantityPane.add(new JLabel("Enter your quantity"));
quantityPane.add(quantityText = new JTextField("", 5));
//添加
paramPane.add(customerPane);
paramPane.add(namePane);
paramPane.add(typePane);
paramPane.add(sizePane);
paramPane.add(toppingPane);
paramPane.add(speedPane);
paramPane.add(quantityPane);
cp.add(paramPane,BorderLayout.WEST);
JPanel buttonPane = new JPanel(); //设置烤制pizza的按扭
button1 = new JButton("MakePizza"); //开始做pizza
buttonPane.add(button1);
button1.addActionListener(new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
getQuantity();
log.append("Quantity: " + quantity + "\n"+"wait plaese......\n"); //文本信息显示
makePizza();
}
});
button2 = new JButton("Finish"); //pizza烤制完成
buttonPane.add(button2);
button2.addActionListener(new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
finishSale();
}
});
cp.add(buttonPane,BorderLayout.SOUTH);
}
public PizzaStoreFrame() {
// TODO Auto-generated constructor stub
}
public void setPizzaType(String name,int price)//设置pizza 种类
{
pizzaType=new PizzaType(name,price);
}
public void getType(String aType)
{
type = aType;
}
public void getSize(String aSize)
{
size = Integer.parseInt(aSize);
}
public void setTopping(String aTopping)
{
if (aTopping.equals("Pineapple"))
topping = new Topping("Pineapple");
else if(aTopping.equals("Mushroom"))
topping = new Topping("Mushroom");
else if(aTopping.equals("Gallic"))
topping = new Topping("Gallic");
}
public void getSpeed(String aSpeed)
{
if (aSpeed.equals("Fast"))
speed = new Fast();
else if(aSpeed.equals("Normal"))
speed = new Normal();
else if(aSpeed.equals("Slow"))
speed = new Slow();
}
public void getQuantity()
{
if(quantityText.getText().length()==0)
quantity=1;
else
quantity = Integer.parseInt(quantityText.getText());
}
public int getNextSaleID() //读取交易标识
{
workID++;
return workID;
}
//添加pizza
public void makePizza()
{
if(speed==null)
speed=new Fast();
if(ST == 0)
pizzaStore.addBakeJob(pizzaType, type, size, topping,
speed, quantity, SF);
else
pizzaStore.addDiliverJob(pizzaType, type, size, topping,
speed, quantity, SF);
SF = 1;
button2.setEnabled(true);
}
//结束一个交易,并更新烤制列表
public void finishSale()
{
log.append(pizzaStore.getPrice(ST));
log.append("Sale No." + getNextSaleID() + "------------------------------------->\n");
bakeJob = pizzaStore.makePizza(workID);
jobFrame.setList(bakeJob);
pizzas = pizzaStore.getAPizza();
for(int i = 0; i < pizzas.size(); i++)
{
Pizza p = (Pizza)pizzas.get(i);
//向数据库添加信息
try
{
Connect.getConnection(); //连接数据库
Connect.takepizza(p.getPizzaType().getTypeName(), p.getQuantity());
ResultSet rs=Connect.checkquantity(); //检查pizza的库存量
System.out.println("check pizza storage");
while(rs.next())
{
String info="pizza name:"+rs.getString(1)+" basetype:"+rs.getString(2)+" size:"+rs.getString(3)+" need to update storage!";
System.out.println("--------------Warning-----------------");
System.out.println(info);
WarnStoreDialog ws=new WarnStoreDialog(PizzaStoreFrame.this);
ws.setDialog(info);
ws.show();
}
int price=p.getPrice();
if(ST==1)
price=price+5;
Connect.addpizzabake(p.getPizzaType().getTypeName(),p.getBaseTypeName(),p.getToppingName(),this.ST,p.getQuantity(),p.getBakeSpeedName(),price,price*0.1);
System.out.print("successfully insert!\n");
}
catch(SQLException e)
{
e.printStackTrace();
}
}
//重新设置标识
SF = 0;
ST = 0;
}
// 注意使用标志信息来标识pizza交易的信息
private int ST = 0; //标志销售类型,0为sendhome,1为sellnow
private int SF = 0; //标志是否为新的交易
private static int workID = 1; //工作号
private ArrayList pizzas; //保存pizza信息的数组
private PizzaType pizzaType=new PizzaType("Supreme",30);
private String type="Thick";
private int size=5;
private Topping topping=new Topping("Pineapple");
private BakeSpeed speed;
private int quantity;
private BakeJobFrame jobFrame;
private PizzaStore pizzaStore;
private BakeJob bakeJob;
private CustomerFrame CustomerInfor;
private UpdateStoreFrame updateInfo;
private TodayListFrame todayList;
private JTextArea log = null;
String configFile = "";
//相关组件
private JPanel namePane;
private JRadioButton supremeB;
private JRadioButton hawaiiB;
private JRadioButton meatLoverB;
private JRadioButton seafoodB;
private JPanel typePane;
private JRadioButton ThickB;
private JRadioButton ThinB;
private JRadioButton SpecialB;
private JPanel sizePane;
private JRadioButton size5;
private JRadioButton size6;
private JRadioButton size7;
private JRadioButton size8;
private JPanel toppingPane;
private JRadioButton PineappleB;
private JRadioButton MushroomB;
private JRadioButton GallicB;
private JPanel speedPane;
private JRadioButton FastB;
private JRadioButton NormalB;
private JRadioButton SlowB;
private JPanel quantityPane;
private JTextField quantityText;
private JPanel customerPane;
private JRadioButton sendhome;
private JRadioButton sellNow;
private JButton button1;
private JButton button2;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -