⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 originalclientbillingui.txt

📁 挺好的JAVA例子,可用MYSQL,ACCESS,ORACLE做后台,例子中包括联结及查询等涵数
💻 TXT
📖 第 1 页 / 共 2 页
字号:
        dobText = new Text(clientInfo, SWT.BORDER);
        dobText.setSize(TEXT_FIELD_WIDTH, TEXT_FIELD_HEIGHT);
        dobText.setEditable(false);

        addressText = new Text(clientInfo, SWT.WRAP | SWT.MULTI | SWT.BORDER);
        addressText.setSize(TEXT_FIELD_WIDTH, TEXT_FIELD_HEIGHT * 3);
        addressText.setEditable(false);

        miscInfoText = new Text(clientInfo, SWT.WRAP | SWT.MULTI | SWT.BORDER);
        miscInfoText.setSize(TEXT_FIELD_WIDTH, TEXT_FIELD_HEIGHT * 3);
        miscInfoText.setEditable(false);

        final int LABEL_X = 20;
        final int TEXT_X = 200;

        clientInfo.setLocation(150, 30);

        acctIDLabel.setLocation(LABEL_X, 30);
        acctIDText.setLocation(TEXT_X, 27);

        fnameLabel.setLocation(LABEL_X, 60);
        fnameText.setLocation(TEXT_X, 57);

        snameLabel.setLocation(LABEL_X, 90);
        snameText.setLocation(TEXT_X, 87);

        phoneLabel.setLocation(LABEL_X, 120);
        phoneText.setLocation(TEXT_X, 117);

        emailLabel.setLocation(LABEL_X, 150);
        emailText.setLocation(TEXT_X, 147);

        dobLabel.setLocation(LABEL_X, 180);
        dobText.setLocation(TEXT_X, 177);

        addressLabel.setLocation(LABEL_X, 210);
        addressText.setLocation(TEXT_X, 207);

        miscInfoLabel.setLocation(LABEL_X, 280);
        miscInfoText.setLocation(TEXT_X, 277);
    }

    private void setupFileMenu() {
        //create the menu bar
        Menu menu = new Menu(shell, SWT.BAR);
        shell.setMenuBar(menu);

        //add the File option to it
        MenuItem file = new MenuItem(menu, SWT.CASCADE);
        file.setText("File");

        //create a menu for the File option
        Menu filemenu = new Menu(shell, SWT.DROP_DOWN);
        file.setMenu(filemenu);

        //add MenuItems to the File menu
        MenuItem aboutItem = new MenuItem(filemenu, SWT.PUSH);
        aboutItem.setText("About...");

        MenuItem quitItem = new MenuItem(filemenu, SWT.PUSH);
        quitItem.setText("Quit");

        //add a listener for the action
        quitItem.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event e) {
                shell.dispose();
            }
        });

        aboutItem.addListener(SWT.Selection, new Listener() {
            private Image aboutImage;
            private Shell aboutShell;

            public void handleEvent(Event e) {

                aboutShell = new Shell(shell, SWT.DIALOG_TRIM);
                aboutShell.setSize(200, 250);
                aboutShell.setText("About...");

                //load an Image
                aboutImage = new Image(display, "splash.jpg");

                aboutShell.addPaintListener(new PaintListener() {
                    public void paintControl(PaintEvent e) {
                        //Get the graphics context
                        GC gc = new GC(aboutShell);
                        //Write a string to the shell
						gc.drawString("Client Billing Application " +VERSION, 30, 10);

                        //draw a blue rectangle
                        Color blue = display.getSystemColor(SWT.COLOR_BLUE);
                        gc.setForeground(blue);
                        gc.drawRectangle(30, 30, 135, 165);

                        //draw an image
                        gc.drawImage(aboutImage, 48, 48);
                    }
                });

                aboutShell.addDisposeListener(new DisposeListener() {
                    public void widgetDisposed(DisposeEvent e) {
                        //when the shell is closed, dispose of the Image
                        aboutImage.dispose();
                    }
                });
                aboutShell.open();

            }

        });
    }

    private void setupTransPane() {

        transItem = new TabItem(folder, SWT.NONE);
        transItem.setText("&Transactions");
        transPane = new Composite(folder, SWT.NONE);
        transItem.setControl(transPane);

        Group transInfo = new Group(transPane, SWT.NONE);
        transInfo.setText("Client Transactions:");

        infoTable =
            new Table(
                transInfo,
                SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);

        transInfo.setSize(450, 350);
        transInfo.setLocation(150, 30);

        infoTable.setLocation(20, 20);
        infoTable.setSize(410, 160);

        infoTable.setLinesVisible(true);
        infoTable.setHeaderVisible(true);

        infoTable.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent arg0) {
                setMode(VIEW_MODE);
                int id = infoTable.getSelectionIndex();
                Transaction current = processor.getTransaction(id);
                idText.setText("" + current.transactionID);
                amtText.setText(current.dollarAmount());
                dateText.setText(current.date);
                descText.setText(current.description);
            }

        });

        TableColumn number = new TableColumn(infoTable, SWT.CENTER);
        number.setText("ID");
        number.setWidth(58);

        TableColumn amount = new TableColumn(infoTable, SWT.RIGHT);
        amount.setText("Amount");
        amount.setWidth(80);

        TableColumn date = new TableColumn(infoTable, SWT.RIGHT);
        date.setText("Date");
        date.setWidth(80);

        TableColumn desc = new TableColumn(infoTable, SWT.LEFT);
        desc.setText("Description");
        desc.setWidth(171);

        Label totalLabel = new Label(transInfo, SWT.NONE);
        totalLabel.setText("Total:");
        totalLabel.pack();

        totalText = new Text(transInfo, SWT.BORDER | SWT.RIGHT);
        totalText.setEditable(false);
        totalText.setSize(80, 20);

        totalText.setLocation(80, 187);
        totalLabel.setLocation(26, 190);

        Label idLabel = new Label(transInfo, SWT.NONE);
        idLabel.setText("ID:");
        idLabel.pack();
        Label amtLabel = new Label(transInfo, SWT.NONE);
        amtLabel.setText("Amount:");
        amtLabel.pack();
        Label descLabel = new Label(transInfo, SWT.NONE);
        descLabel.setText("Description:");
        descLabel.pack();
        Label dateLabel = new Label(transInfo, SWT.NONE);
        dateLabel.setText("Date");
        dateLabel.pack();

        idText = new Text(transInfo, SWT.SINGLE | SWT.BORDER);
        idText.setSize(80, 20);
        idText.setEditable(false);
        amtText = new Text(transInfo, SWT.SINGLE | SWT.BORDER);
        amtText.setSize(80, 20);
        amtText.setEditable(false);
        dateText = new Text(transInfo, SWT.SINGLE | SWT.BORDER);
        dateText.setSize(80, 20);
        dateText.setEditable(false);
        descText = new Text(transInfo, SWT.MULTI | SWT.BORDER | SWT.WRAP);
        descText.setSize(190, 70);
        descText.setEditable(false);

        int LABEL_X = 26;
        int LABEL_Y = 230;
        int LABEL_YDIF = 25;
        int TEXT_YOFF = -3;
        int TEXT_X = 80;

        idLabel.setLocation(LABEL_X, LABEL_Y);
        idText.setLocation(TEXT_X, LABEL_Y + TEXT_YOFF);

        amtLabel.setLocation(LABEL_X, LABEL_Y + LABEL_YDIF);
        amtText.setLocation(TEXT_X, LABEL_Y + LABEL_YDIF + TEXT_YOFF);

        dateLabel.setLocation(LABEL_X, LABEL_Y + 2 * LABEL_YDIF);
        dateText.setLocation(TEXT_X, LABEL_Y + 2 * LABEL_YDIF + TEXT_YOFF);

        descLabel.setLocation(LABEL_X + 150, LABEL_Y);
        descText.setLocation(TEXT_X + 160, LABEL_Y + TEXT_YOFF);

        newButton = new Button(transInfo, SWT.PUSH);
        newButton.setText("&New");
        newButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent arg0) {
                setMode(ADD_MODE);
            }

        });

        delButton = new Button(transInfo, SWT.PUSH);
        delButton.setText("&Delete");
        delButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent arg0) {
                MessageBox msgBox =
                    new MessageBox(
                        shell,
                        SWT.APPLICATION_MODAL | SWT.YES | SWT.NO);
                msgBox.setText("Confirm Deletion");
                msgBox.setMessage(
                    "Are you certain you wish to delete the selected transaction?");
                int index = infoTable.getSelectionIndex();
                if (index >= 0 && msgBox.open() == SWT.YES) {
                    processor.deleteTransaction(index);
                    refreshData();
                }
            }
        });

        editButton = new Button(transInfo, SWT.PUSH);
        editButton.setText("&Edit");
        editButton.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent arg0) {
                editIndex = infoTable.getSelectionIndex();
                setMode(EDIT_MODE);
            }

        });

        saveButton = new Button(transInfo, SWT.PUSH);
        saveButton.setText("&Save");
        saveButton.setEnabled(false);
        saveButton.addSelectionListener(new SaveButtonListener());

        cancelButton = new Button(transInfo, SWT.PUSH);
        cancelButton.setText("&Cancel");
        cancelButton.setEnabled(false);
        cancelButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent arg0) {
                setMode(VIEW_MODE);
            }

        });

        final int AREA_WIDTH = 412;

        final int BUTTONS_X = 20;
        final int BUTTONS_Y = 310;
        final int BUTTON_WIDTH = AREA_WIDTH / 6;
        final int BUTTON_HEIGHT = 20;

        newButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
        delButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
        editButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);

        saveButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
        cancelButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);

        newButton.setLocation(BUTTONS_X, BUTTONS_Y);
        delButton.setLocation(BUTTONS_X + BUTTON_WIDTH, BUTTONS_Y);
        editButton.setLocation(BUTTONS_X + 2 * BUTTON_WIDTH, BUTTONS_Y);

        saveButton.setLocation(BUTTONS_X + 4 * BUTTON_WIDTH, BUTTONS_Y);
        cancelButton.setLocation(BUTTONS_X + 5 * BUTTON_WIDTH, BUTTONS_Y);
    }

    private String toDollarAmt(int amt) {
        boolean neg = false;
        if (amt < 0) {
            neg = true;
            amt = -amt;
        }
        int dollars = amt / 100;
        int cents = amt % 100;
        return (neg ? "-" : "")
            + dollars
            + "."
            + (cents < 10 ? "0" : "")
            + cents;
    }

    private int toCentsAmt(String amt) throws NumberFormatException {
        //convert dollars and cents String, into integer cents
        int dollars = 0;
        int cents = 0;
        int val = 0;
        StringTokenizer st = new StringTokenizer(amt, ".");

        if (st.countTokens() == 1) {
            if (amt.charAt(0) == '.')
                cents = Integer.parseInt(st.nextToken());
            else
                dollars = Integer.parseInt(st.nextToken());
        }
        else if (st.countTokens() == 2) {
            dollars = Integer.parseInt(st.nextToken());
            cents = Integer.parseInt(st.nextToken());
        }
        if (cents < 0)
            throw new NumberFormatException();
        while (cents > 100)
            cents /= 10;

        val = dollars * 100;
        if (dollars > 0)
            val += cents;
        else
            val -= cents;
        return val;
    }

    class SaveButtonListener extends SelectionAdapter {

        //respond to presses of the Save button on the transaction page
        public void widgetSelected(SelectionEvent arg0) {
            int transID;

            try {
                transID = Integer.parseInt(idText.getText());
            }
            catch (NumberFormatException e) {
                MessageBox msgBox =
                    new MessageBox(shell, SWT.APPLICATION_MODAL | SWT.OK);
                msgBox.setText("Input Error");
                msgBox.setMessage(
                    "The transaction ID entered must be a valid integer unique among transactions for this client.");
                msgBox.open();
                return;
            }

            int amt = 0;
            try {
                amt = toCentsAmt(amtText.getText());
            }
            catch (NumberFormatException e) {
                MessageBox msgBox =
                    new MessageBox(shell, SWT.APPLICATION_MODAL | SWT.OK);
                msgBox.setText("Input Error");
                msgBox.setMessage("The transaction amount was not valid.");
                msgBox.open();
                return;
            }

            boolean success = false;
            if (activeMode == ADD_MODE) {
                success =
                    processor.addTransaction(
                        transID,
                        amt,
                        dateText.getText(),
                        descText.getText());
            }
            else if (activeMode == EDIT_MODE) {
                success =
                    processor.updateTransaction(
                        editIndex,
                        transID,
                        amt,
                        dateText.getText(),
                        descText.getText());
            }
            if (!success) {
                MessageBox msgBox =
                    new MessageBox(shell, SWT.APPLICATION_MODAL | SWT.OK);
                msgBox.setText("Input Error");
                msgBox.setMessage(
                    "The Transaction ID entered must be a valid integer unique among transactions for this client.");
                msgBox.open();
                return;
            }

            refreshData();
            setMode(VIEW_MODE);
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -