📄 pizzaorderresult.java
字号:
package GUI;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import OrderInf.*;
import PizzaProduct.Pizza;
import Dbprocess.*;
public class PizzaOrderResult extends Dialog {
//DBmanager dbm = new DBmanager();
private Text text;
protected Object result;
protected Pizza[] pizzas;
protected Shell shell;
protected boolean instore;
protected CustomerInf ci;
int total;
/**
* Create the dialog
* @param parent
* @param style
*/
public PizzaOrderResult(Shell parent, int style) {
super(parent, style);
}
/**
* Create the dialog
* @param parent
*/
public PizzaOrderResult(Shell parent,Pizza[] pizzas,boolean instore) {
this(parent, SWT.NONE);
this.pizzas=pizzas;
this.instore=instore;
}
public PizzaOrderResult(Shell parent,Pizza[] pizzas,boolean instore,CustomerInf ci) {
this(parent, SWT.NONE);
this.pizzas=pizzas;
this.instore=instore;
this.ci = ci;
}
public CustomerInf getCi() {
return ci;
}
public void setCi(CustomerInf ci) {
this.ci = ci;
}
/**
* Open the dialog
* @return the result
*/
public Object open() {
createContents();
shell.open();
shell.layout();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
return result;
}
/**
* Create contents of the dialog
*/
protected void createContents() {
total=0;
int i;
shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setSize(500, 375);
shell.setText("The Pizzas Ordered");
text = new Text(shell, SWT.WRAP | SWT.READ_ONLY | SWT.BORDER);
text.setBounds(10, 10, 474, 279);
for(i=0;i<pizzas.length;i++){
if(instore)
pizzas[i].setInstore("Y");
else
pizzas[i].setInstore("N");
pizzas[i].computePrice();
total=total+pizzas[i].getPrice();
text.setText(text.getText()+"\r\n"+pizzas[i].toString()+".\r\n The cost is "+pizzas[i].getPrice());
}
text.setText(text.getText()+"\r\n"+"All you pizza will roast in "+pizzas[0].getRoutines()+"minutes." +"\r\n" );
if (instore){
text.setText(text.getText()+"The total price is $"+ total);
}
else{
total=total+5;
text.setText(text.getText()+ci.toString()+"\r\n");
text.setText(text.getText()+"The cost of transport is $5.\r\n The total price is $"+ total);
}
final Button button = new Button(shell, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if(instore){
PizzaOrders po = new PizzaOrders(pizzas);
po.setTotalprice(total);
// Customer cus = new Customer(po);
DBmanager dbm = new DBmanager();
dbm.insertDB(po);
dbm.updateDBpiz(pizzas);
dbm.close();
}
else{
PizzaOrders po = new PizzaOrders(pizzas);
po.setTotalprice(total);
// Customer cus = new Customer(ci,po);
DBmanager dbm = new DBmanager();
dbm.insertDB(po);
dbm.updateDBpiz(pizzas);
dbm.close();
}
shell.close();
}
});
button.setText("确定");
button.setBounds(98, 305, 63, 22);
final Button button_1 = new Button(shell, SWT.NONE);
button_1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
shell.close();
}
});
button_1.setText("返回");
button_1.setBounds(298, 305, 57, 22);
//
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -