为什么我的程序不显示复合材料?

时间:2016-05-18 17:31:53

标签: java

当我运行程序时,它不会在我的主窗口中显示复合材料。我需要将复合添加到shell吗?

public class OrdersMenu {

    protected Shell shell;
    private Text text;
    private Composite compositeMenu;
    private Composite compositeBurger;
    private Composite compositeChicken;

    /**
     * Launch the application.
     * @param args
     */
    public static void main(String[] args) {
        try {
            OrdersMenu window = new OrdersMenu();
            window.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Open the window.
     */
    public void open() {
        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(450, 300);
        shell.setText("SWT Application");
        shell.setLayout(new StackLayout());

        Composite compositeMenu = new Composite(shell, SWT.NONE);
        compositeMenu.setLayout(null);
        compositeMenu.setVisible(true);

        Composite compositeBurger = new Composite(shell, SWT.NONE);
        compositeBurger.setLayout(null);
        compositeBurger.setVisible(false);

        Composite compositeChicken = new Composite(shell, SWT.NONE);
        compositeChicken.setLayout(null);
        compositeChicken.setVisible(false);

        Button btnBurgerButton = new Button(compositeMenu, SWT.NONE);
        btnBurgerButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                compositeBurger.setVisible(true);
                compositeMenu.setVisible(false);
            }
        });
        btnBurgerButton.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
        btnBurgerButton.setFont(SWTResourceManager.getFont("Times New Roman", 19, SWT.BOLD));
        btnBurgerButton.setBounds(96, 84, 94, 50);
        btnBurgerButton.setText("Burger");

        Button btnChickenButton = new Button(compositeMenu, SWT.NONE);
        btnChickenButton.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
        btnChickenButton.setFont(SWTResourceManager.getFont("Times New Roman", 19, SWT.BOLD));
        btnChickenButton.setBounds(251, 84, 94, 50);
        btnChickenButton.setText("Chicken");

        text = new Text(compositeMenu, SWT.BORDER);
        text.setBounds(116, 201, 204, 19);

        Label lblNewLabel = new Label(compositeMenu, SWT.NONE);
        lblNewLabel.setFont(SWTResourceManager.getFont("Times New Roman", 19, SWT.BOLD | SWT.ITALIC));
        lblNewLabel.setBounds(165, 176, 94, 19);
        lblNewLabel.setText("Your Oders");



        Button bBurgerCheckBox = new Button(compositeBurger, SWT.CHECK);
        bBurgerCheckBox.setBounds(172, 32, 94, 18);
        bBurgerCheckBox.setText("Burger");

        Button bFriesCheckBox = new Button(compositeBurger, SWT.CHECK);
        bFriesCheckBox.setBounds(172, 73, 94, 18);
        bFriesCheckBox.setText("Fries");

        Button bDrinkCheckBox = new Button(compositeBurger, SWT.CHECK);
        bDrinkCheckBox.setBounds(172, 115, 94, 18);
        bDrinkCheckBox.setText("Drink");

        Button bDoneButton = new Button(compositeBurger, SWT.NONE);
        bDoneButton.setBounds(172, 162, 94, 50);
        bDoneButton.setText("Done!");



        Button cChickenCheckBox = new Button(compositeChicken, SWT.CHECK);
        cChickenCheckBox.setText("Chicken");
        cChickenCheckBox.setBounds(176, 21, 94, 18);

        Button cFriesCheckBox = new Button(compositeChicken, SWT.CHECK);
        cFriesCheckBox.setText("Fries");
        cFriesCheckBox.setBounds(176, 62, 94, 18);

        Button cDrinkCheckBox = new Button(compositeChicken, SWT.CHECK);
        cDrinkCheckBox.setText("Drink");
        cDrinkCheckBox.setBounds(176, 104, 94, 18);

        Button cDoneButton = new Button(compositeChicken, SWT.NONE);
        cDoneButton.setText("Done!");
        cDoneButton.setBounds(176, 151, 94, 50);

    }
}

0 个答案:

没有答案