📄 automachine.java
字号:
package version2;
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.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import com.swtdesigner.SWTResourceManager;
public class automachine {
protected Shell shell;
machinebean mb = new machinebean();
/**
* Launch the application
* @param args
*/
public static void main(String[] args) {
try {
automachine window = new automachine();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window
*/
public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
/**
* Create contents of the window
*/
protected void createContents() {
shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application");
final Label remainLabel = new Label(shell, SWT.NONE);
remainLabel.setText("剩余:");
remainLabel.setBounds(25, 50, 30, 12);
final Label label = new Label(shell, SWT.NONE);
label.setText(mb.getJuiceNum());
label.setBounds(60, 52, 30, 12);
final Label label_1 = new Label(shell, SWT.NONE);
label_1.setText(mb.getBeerNum());
label_1.setBounds(119, 52, 30, 12);
final Label label_2 = new Label(shell, SWT.NONE);
label_2.setText("请投币");
label_2.setBounds(290, 30, 50, 22);
final Label label_3 = new Label(shell, SWT.NONE);
label_3.setText("信息框");
label_3.setBounds(295, 180, 48, 12);
final Label label_4 = new Label(shell, SWT.NONE);
label_4.setText("5角");
label_4.setBounds(265, 255, 30, 12);
final Label label_5 = new Label(shell, SWT.NONE);
label_5.setText("1元");
label_5.setBounds(335, 255, 30, 12);
final Label label_6 = new Label(shell, SWT.NONE);
label_6.setText(mb.getJiaoNum());
label_6.setBounds(266, 221, 12, 12);
final Label label_7 = new Label(shell, SWT.NONE);
label_7.setText("枚");
label_7.setBounds(285, 220, 30, 12);
final Label label_8 = new Label(shell, SWT.NONE);
label_8.setText("枚");
label_8.setBounds(360, 220, 30, 12);
final Label label_9 = new Label(shell, SWT.NONE);
label_9.setText(mb.getYuanNum());
label_9.setBounds(335, 220, 30, 12);
final Label label_10 = new Label(shell, SWT.NONE);
label_10.setText("出口");
label_10.setBounds(95, 180, 30, 12);
final Label label_11 = new Label(shell, SWT.NONE);
label_11.setText("饮料出口");
label_11.setBounds(48, 221, 53, 12);
final Label label_12 = new Label(shell, SWT.NONE);
label_12.setText("退币口");
label_12.setBounds(120, 220, 48, 12);
final Label label_13 = new Label(shell, SWT.NONE);
label_13.setText("零钱找完灯");
label_13.setBounds(429, 77, 63, 12);
final Label label_14 = new Label(shell, SWT.NONE);
label_14.setBackground(SWTResourceManager.getColor(0, 0, 0));
label_14.setBounds(438, 59, 30, 12);
final Label label_15 = new Label(shell, SWT.NONE);
label_15.setText("价格0.5元");
label_15.setBackground(SWTResourceManager.getColor(255, 0, 0));
label_15.setBounds(48, 95, 53, 18);
final Label label_16 = new Label(shell, SWT.NONE);
label_16.setText("价格1.5元");
label_16.setBackground(SWTResourceManager.getColor(255, 0, 0));
label_16.setBounds(119, 95, 63, 18);
final Label label_17 = new Label(shell, SWT.NONE);
label_17.setText("总计投入:");
label_17.setBounds(215, 205, 48, 12);
final Label label_18 = new Label(shell, SWT.NONE);
label_18.setText("元");
label_18.setBounds(290, 205, 30, 12);
final Label label_19 = new Label(shell, SWT.NONE);
label_19.setText("0");
label_19.setBounds(270, 205, 30, 12);
final Label label_20 = new Label(shell, SWT.NONE);
label_20.setText("已投入");
label_20.setBounds(215, 220, 42, 12);
final Label label_21 = new Label(shell, SWT.NONE);
label_21.setText("已储存");
label_21.setBounds(215, 239, 48, 12);
final Label label_22 = new Label(shell, SWT.NONE);
label_22.setText(mb.getJiaoNumHave());
label_22.setBounds(265, 239, 12, 12);
final Label label_23 = new Label(shell, SWT.NONE);
label_23.setText("枚");
label_23.setBounds(285, 238, 22, 12);
final Label label_24 = new Label(shell, SWT.NONE);
label_24.setText(mb.getYuanNumHave());
label_24.setBounds(335, 237, 8, 12);
final Label label_25 = new Label(shell, SWT.NONE);
label_25.setText("枚");
label_25.setBounds(360, 237, 22, 12);
final Label label_26 = new Label(shell, SWT.NONE);
label_26.setBounds(119, 238, 42, 29);
final Label label_27 = new Label(shell, SWT.NONE);
label_27.setBounds(45, 239, 45, 28);
final Label label_28 = new Label(shell, SWT.NONE);
label_28.setText("请选择饮料");
label_28.setBounds(65, 30, 74, 12);
final Button button = new Button(shell, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
if (mb.getJuice()==true) {
label_27.setText("1瓶橙汁");
label_22.setText(mb.getJiaoNumHave());
label_24.setText(mb.getYuanNumHave());
}
label.setText(mb.getJuiceNum());
label_6.setText(mb.getJiaoNum());
label_9.setText(mb.getYuanNum());
if (mb.getFlag()==true){
label_14.setBackground(SWTResourceManager.getColor(255, 0, 0));
mb.resetFlag();
}
else label_14.setBackground(SWTResourceManager.getColor(0, 0, 0));
if (mb.getJuiceFlag()==false) label_15.setBackground(SWTResourceManager.getColor(255, 0, 0));
if (mb.getBeerFlag()==false) label_16.setBackground(SWTResourceManager.getColor(255, 0, 0));
label_19.setText(mb.getSum());
}
});
button.setText("Juice");
button.setBounds(53, 67, 48, 22);
final Button beerButton = new Button(shell, SWT.NONE);
beerButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
if (mb.getBeer()==true) {
label_27.setText("1瓶啤酒");
label_22.setText(mb.getJiaoNumHave());
label_24.setText(mb.getYuanNumHave());
}
label_1.setText(mb.getBeerNum());
label_6.setText(mb.getJiaoNum());
label_9.setText(mb.getYuanNum());
if (mb.getFlag()==true){
label_14.setBackground(SWTResourceManager.getColor(255, 0, 0));
mb.resetFlag();
}
else label_14.setBackground(SWTResourceManager.getColor(0, 0, 0));
if (mb.getJuiceFlag()==false) label_15.setBackground(SWTResourceManager.getColor(255, 0, 0));
if (mb.getBeerFlag()==false) label_16.setBackground(SWTResourceManager.getColor(255, 0, 0));
label_19.setText(mb.getSum());
}
});
beerButton.setText("Beer");
beerButton.setBounds(112, 67, 48, 22);
final Button button_1 = new Button(shell, SWT.NONE);
button_1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
mb.addJiao();
label_6.setText(mb.getJiaoNum());
label_22.setText(mb.getJiaoNumHave());
label_24.setText(mb.getYuanNumHave());
if (mb.getJuiceFlag()==true) label_15.setBackground(SWTResourceManager.getColor(0, 255, 0));
if (mb.getBeerFlag()==true) label_16.setBackground(SWTResourceManager.getColor(0, 255, 0));
label_19.setText(mb.getSum());
}
});
button_1.setText("5角");
button_1.setBounds(218, 67, 48, 22);
final Button button_2 = new Button(shell, SWT.NONE);
button_2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
mb.addYuan();
label_9.setText(mb.getYuanNum());
label_22.setText(mb.getJiaoNumHave());
label_24.setText(mb.getYuanNumHave());
if (mb.getJuiceFlag()==true) label_15.setBackground(SWTResourceManager.getColor(0, 255, 0));
if (mb.getBeerFlag()==true) label_16.setBackground(SWTResourceManager.getColor(0, 255, 0));
label_19.setText(mb.getSum());
}
});
button_2.setText("1元");
button_2.setBounds(288, 67, 48, 22);
final Button button_3 = new Button(shell, SWT.NONE);
button_3.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
label_26.setText(mb.getYuanNum()+"个1元\n"+mb.getJiaoNum()+"个5角");
mb.retMoney();
mb.resetFlag();
label_15.setBackground(SWTResourceManager.getColor(255, 0, 0));
label_16.setBackground(SWTResourceManager.getColor(255, 0, 0));
label_14.setBackground(SWTResourceManager.getColor(0, 0, 0));
label_6.setText(mb.getJiaoNum());
label_9.setText(mb.getYuanNum());
label_19.setText(mb.getSum());
label_22.setText(mb.getJiaoNumHave());
label_24.setText(mb.getYuanNumHave());
}
});
button_3.setText("退币");
button_3.setBounds(363, 67, 48, 22);
final Group group = new Group(shell, SWT.NONE);
group.setBounds(10, 31, 193, 118);
final Group group_1 = new Group(shell, SWT.NONE);
group_1.setBounds(215, 30, 208, 118);
final Group group_2 = new Group(shell, SWT.NONE);
group_2.setBounds(10, 180, 193, 134);
final Group group_3 = new Group(shell, SWT.NONE);
group_3.setBounds(215, 180, 208, 134);
//
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -