📄 automachine.java
字号:
package version1;
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, 36, 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(266, 263, 30, 12);
final Label label_5 = new Label(shell, SWT.NONE);
label_5.setText("1元");
label_5.setBounds(335, 263, 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, 52, 30, 12);
final Label label_18 = new Label(shell, SWT.NONE);
label_18.setText(mb.getYuanNumHave());
label_18.setBounds(335, 245, 12, 12);
final Label label_17 = new Label(shell, SWT.NONE);
label_17.setText("枚");
label_17.setBounds(285, 245, 30, 12);
final Label label_16 = new Label(shell, SWT.NONE);
label_16.setText(mb.getJiaoNumHave());
label_16.setBounds(266, 245, 12, 12);
final Label label_19 = new Label(shell, SWT.NONE);
label_19.setText("枚");
label_19.setBounds(360, 245, 20, 12);
final Label label_22 = new Label(shell, SWT.NONE);
label_22.setBounds(48, 239, 55, 21);
final Label label_23 = new Label(shell, SWT.NONE);
label_23.setBounds(110, 240, 55, 21);
final Button button = new Button(shell, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
if (mb.getJuice()==true) {
label_22.setText("1瓶果汁");
label_16.setText(mb.getJiaoNumHave());
label_18.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));
}
}
});
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_22.setText("1瓶啤酒");
label_16.setText(mb.getJiaoNumHave());
label_18.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));
}
}
});
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_16.setText(mb.getJiaoNumHave());
}
});
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_18.setText(mb.getYuanNumHave());
}
});
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_23.setText(mb.getYuanNum()+"个1元\n"+mb.getJiaoNum()+"个5角");
mb.retMoney();
mb.resetFlag();
label_14.setBackground(SWTResourceManager.getColor(0, 0, 0));
label_6.setText(mb.getJiaoNum());
label_9.setText(mb.getYuanNum());
label_16.setText(mb.getJiaoNumHave());
label_18.setText(mb.getYuanNumHave());
}
});
button_3.setText("退币");
button_3.setBounds(363, 67, 48, 22);
final Label label_15 = new Label(shell, SWT.NONE);
label_15.setText("请选择饮料");
label_15.setBounds(70, 30, 63, 12);
final Label label_21 = new Label(shell, SWT.NONE);
label_21.setText("已储存");
label_21.setBounds(218, 248, 43, 12);
final Group group_1 = new Group(shell, SWT.NONE);
group_1.setBounds(205, 31, 218, 113);
final Label label_20 = new Label(shell, SWT.NONE);
label_20.setBounds(217, 221,43, 12);
label_20.setText("已投入");
final Group group = new Group(shell, SWT.NONE);
group.setBounds(13, 31, 169, 113);
final Group group_2 = new Group(shell, SWT.NONE);
group_2.setBounds(13, 180, 169, 122);
final Group group_3 = new Group(shell, SWT.NONE);
group_3.setBounds(205, 180, 218, 122);
//
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -