PosOrderMainWin.java
//list
final List list = new List(c2, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL|SWT.SIMPLE);//
list.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
@Override
//取得当前选取的项目
public void widgetSelected(SelectionEvent e) {
// String select[] = list.getSelection();
// for(int i=0; i < select.length; i ++)
// {
// System.out.println(select[i]);
// }
// list Data
// new CustomDialog(Display.getCurrent().getActiveShell(),
// ManName, ClassName, OrderName, account, SimplePrice, allPrice
// ).open();
new CustomDialog(Display.getCurrent().getActiveShell(), list.getSelection()[0]).open();
}
});
//list Data
String ManName = "Bill";
String ClassName = "套餐";
String OrderName = "西红柿";
int account = 2;
double SimplePrice = 12.0;
double allPrice = SimplePrice * account;
// list.setItems(new String[] {"one", "two", "three"});//初始发list
list.add(ManName+ " 订了 " + OrderName + "(" + ClassName + ") " + account + "件, 单价:" + SimplePrice +", 总价:" + allPrice);
// list.add("five", 2);//在list的第二个位置加值
// list.add("ddddd");
// list.setBounds(100, 50, 50, 50);
CustomDialog.java
public class CustomDialog extends Dialog {
protected Object result;
protected Shell shell;
String ManName;
String ClassName;
String OrderName;
int account;
double SimplePrice;
double allPrice;
String context;
public CustomDialog(Shell parent, String ManName, String ClassName, String OrderName, int account, double SimplePrice, double allPrice) {
super(parent, SWT.NONE);
this.ManName = ManName;
this.ClassName = ClassName;
this.OrderName = OrderName;
this.account = account;
this.SimplePrice = SimplePrice;
this.allPrice = allPrice;
this.context = ManName+ " 订了 " + OrderName + "(" + ClassName + ") " + account + "件, 单价:" + SimplePrice +", 总价:" + allPrice;
}
public CustomDialog(Shell parent, String context) {
super(parent, SWT.NONE);
this.context = context;
}
public Object open() {
createContents();
shell.open();
shell.layout();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
return result;
}
protected void createContents() {
shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setSize(300, 100);
shell.setText("Order Details Dialog");
shell.setLocation(400, 400);
// final Button button = new Button(shell, SWT.NONE);
final Text txt = new Text(shell, SWT.NONE);
txt.setText(context);
txt.setSize(300, 20);
// txt.setBounds(127, 74, 44, 23);
// button.setBounds(127, 74, 44, 23);
}
}