Package java.awt

Examples of java.awt.Dialog


     */
    public static Dialog getTopModalDialog() {
  return(DialogWaiter.getDialog(new ComponentChooser() {
    public boolean checkComponent(Component comp) {
        if(comp instanceof Dialog) {
      Dialog dialog = (Dialog)comp;
      if(dialog.isModal()) {
          Window[] ow = dialog.getOwnedWindows();
          for(int i = 0; i < ow.length; i++) {
        if(ow[i].isVisible()) {
            return(false);
        }
          }
View Full Code Here


            public void run() {
                assert modalDialogs != null;
               
                int size = modalDialogs.size();
                if (size > 0) {
                    final Dialog awtDialog = (Dialog)modalDialogs.get(size - 1);

                    // In one case, a call to requestFocus() alone does not
                    // bring the AWT dialog to the top. This happens if the
                    // dialog is given a null parent frame. When opened, the dialog
                    // can be hidden by the SWT window even when it obtains focus.
                    // Calling toFront() solves the problem, but...
                    //
                    // There are still problems if the Metal look and feel is in use.
                    // The SWT window will hide the dialog the first time it is
                    // selected. Once the dialog is brought back to the front by
                    // the user, there is no further problem.
                    //
                    // Why? It looks like SWT is not being notified of lost focus when
                    // the Metal dialog first opens; subsequently, when focus is regained, the
                    // focus gain event is not posted to the SwtInputBlocker. 
                    //
                    // The workaround is to use Windows look and feel, rather than Metal.
                    // System.out.println("Bringing to front");

                    awtDialog.requestFocus();
                    awtDialog.toFront();
                }
            }
        });
    }
View Full Code Here

        assert EventQueue.isDispatchThread();    // On AWT event thread
       
        // System-based close
        Window window = event.getWindow();
        if (window instanceof Dialog) {
            final Dialog dialog = (Dialog) window;
            // Defer until later. Bad things happen if
            // handleRemovedDialog() is called directly from
            // this event handler. The Swing dialog does not close
            // properly and its modality remains in effect.
            EventQueue.invokeLater(new Runnable() {
View Full Code Here

     * Показать простой диалог-сообшение.
     * @param title заголовок.
     * @param message сообщение.
     */
    private void showSimpleDialogMessage(String title, String message) {
        final Dialog infoDialog = new JDialog();
        infoDialog.setModal(true);
        infoDialog.setTitle(title);
        infoDialog.setLayout(new GridBagLayout());

        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.BOTH;
        c.insets = new Insets(5, 5, 5, 5);
        c.ipady = 5;
        c.ipadx = 5;

        c.gridx = 0;
        c.gridy = 0;
        infoDialog.add(new JLabel(message), c);

        JButton bttn = new JButton("OK");
        bttn.setAlignmentX(JComponent.CENTER_ALIGNMENT);
        bttn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                infoDialog.dispose();
            }
        });

        c.fill = GridBagConstraints.NONE;
        c.gridy = 2;
        c.ipady = 0;
        c.ipadx = 0;
        infoDialog.add(bttn, c);

        infoDialog.pack();
        infoDialog.setLocationRelativeTo(this);
        infoDialog.setResizable(false);
        infoDialog.setVisible(true);
    }
View Full Code Here

     * Показать подробную информацию о компаниию.
     */
    public void showCompanyInformation() {
        CompanyCell company = (CompanyCell) _cell;

        final Dialog infoDialog = new JDialog();
        infoDialog.setModal(true);
        infoDialog.setTitle("Компания " + company.name());

        infoDialog.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();

        c.fill = GridBagConstraints.BOTH;
        c.insets = new Insets(5, 5, 5, 5);
        c.ipady = 5;
        c.ipadx = 5;

        c.gridx = 0;
        c.gridy = 0;
        infoDialog.add(new JLabel("<html>"
                + "Наименование: <u>" + company.name()
                + "</u></html>"), c);

        c.gridy = 1;
        infoDialog.add(new JLabel("<html>"
                + "Цена: <i>" + company.cost() + " $</i>"
                + "</html>"), c);

        c.gridy = 2;
        infoDialog.add(new JLabel("<html>"
                + "Компенсация в случаи конфискации: <i>"
                + company.confiscationCost() + " $</i>"
                + "</html>"), c);

        c.gridy = 3;
        infoDialog.add(new JLabel("<html>"
                + "Арендная плата (рента): <i>"
                + company.rent() + " $</i>"
                + "</html>"), c);

        c.gridy = 4;
        Color color = HTMLColors.black;
        ILandOwner owner = company.owner();
        if (owner instanceof Player) {
            color = ((Player) owner).color();
        }

        infoDialog.add(new JLabel("<html>"
                + "Владелец: <font color="
                + HTMLColors.getName(color) + ">"
                + company.owner().name() + "</font>"
                + "</html>"), c);

        JButton bttn = new JButton("OK");
        bttn.setAlignmentX(JComponent.CENTER_ALIGNMENT);
        bttn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                infoDialog.dispose();
            }
        });

        c.fill = GridBagConstraints.NONE;
        c.gridx = 0;
        c.gridy = 5;
        infoDialog.add(bttn, c);

        infoDialog.pack();
        infoDialog.setLocationRelativeTo(this);
        infoDialog.setResizable(false);
        infoDialog.setVisible(true);
    }
View Full Code Here

     * Начать новую игру.
     */
    private void startNewGame() {
        _canNewGame = false;

        final Dialog dialog = new JDialog();
        dialog.setModal(true);
        dialog.setTitle("Новая игра");
        dialog.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.BOTH;
        c.insets = new Insets(5, 5, 5, 5);

        c.gridx = 0;
        c.gridy = 0;
        dialog.add(new JLabel("Укажите количество игроков, "
                + "принимающих участие в игре."), c);

        final JSpinner countSpr = new JSpinner(new SpinnerNumberModel(5, 2, 10, 1));
        c.gridy = 1;
        dialog.add(countSpr, c);

        JButton okbttn = new JButton("OK");
        okbttn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                _canNewGame = true;

                GameViewEvent event = new GameViewEvent(this,
                        (Integer) countSpr.getValue());
                fireNewStartedGame(event);

                dialog.dispose();
            }
        });

        c.fill = GridBagConstraints.NONE;
        c.gridy = 2;
        dialog.add(okbttn, c);

        dialog.pack();
        dialog.setLocationRelativeTo(this);
        dialog.setResizable(false);
        dialog.setVisible(true);

        if (_canNewGame == false) {
            setVisible(false);
            dispose();
        }
View Full Code Here

            final CompanyCell companyCell = (CompanyCell) cell;

            if (companyCell.owner() == _gameModel.bank()) {
                _canPlayerBuyLand = true;

                final Dialog dialog = new JDialog();
                dialog.setModal(true);
                dialog.setTitle("Фирма \"" + companyCell.name() + "\"");
                dialog.setLayout(new GridBagLayout());
                GridBagConstraints c = new GridBagConstraints();
                c.fill = GridBagConstraints.BOTH;
                c.insets = new Insets(5, 5, 5, 5);

                c.gridx = 0;
                c.gridy = 0;
                dialog.add(new JLabel("<html>"
                        + "Игрок <font color=" + HTMLColors.getName(p.color()) + ">"
                        + "\"" + p.name() + "\"</font>" + "остановился на ячейки"
                        + " являющейся фирмой <u>\"" + companyCell.name() + "\"</u>"
                        + " принадлежащей Банку.<br>"
                        + "Желаете приобрести указанную фирму за ее номинальную"
                        + " цену <i>" + companyCell.cost() + "$?</i>"
                        + "</html>"), c);

                JButton ybttn = new JButton("Да");
                ybttn.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        _canPlayerBuyLand = false;

                        GameViewEvent event = new GameViewEvent(this, p,
                                companyCell, companyCell.cost());
                        fireMadePlayerBuyLand(event);

                        dialog.dispose();
                    }
                });

                c.fill = GridBagConstraints.VERTICAL;
                c.gridy = 1;
                dialog.add(ybttn, c);

                JButton nbttn = new JButton("Нет");
                nbttn.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        dialog.dispose();
                    }
                });

                c.gridy = 2;
                dialog.add(nbttn, c);

                dialog.pack();
                dialog.setLocationRelativeTo(this);
                dialog.setResizable(false);
                dialog.setVisible(true);

                if (_canPlayerBuyLand == false) {
                    showSimpleDialogMessage("Недостаточно денежных средств",
                            "<html>"
                            + "Игроку <font color=" + HTMLColors.getName(p.color())
                            + ">\"" + p.name() + "\"</font> не хватило денежных "
                            + "средств для покупки фирмы <u>\"" + companyCell.name()
                            + "\"</u>.<br>Необходмо: <i>" + companyCell.cost()
                            + "$.</i><br>Имеется: <i>" + p.money() + "$.</i>"
                            + "</html>");
                }
            } else if (companyCell.owner() != p) {
                final Dialog infoDialog = new JDialog();
                infoDialog.setModal(true);
                infoDialog.setTitle("Фирма \"" + companyCell.name() + "\"");
                infoDialog.setLayout(new GridBagLayout());
                GridBagConstraints c = new GridBagConstraints();
                c.fill = GridBagConstraints.BOTH;
                c.insets = new Insets(5, 5, 5, 5);

                c.gridx = 0;
                c.gridy = 0;

                Color color = HTMLColors.black;
                final ILandOwner owner = companyCell.owner();
                if (owner instanceof Player) {
                    color = ((Player) owner).color();
                }

                infoDialog.add(new JLabel("<html>"
                        + "Игрок <font color=" + HTMLColors.getName(p.color()) + ">"
                        + "\"" + p.name() + "\"</font>" + "остановился на ячейки"
                        + " являющейся фирмой <u>\"" + companyCell.name() + "\"</u>"
                        + " и принадлежащей игроку <font color="
                        + HTMLColors.getName(color) + ">\"" + owner.name()
                        + "\"</font>.<br>"
                        + "Оплатите арендную плату в размере <i>"
                        + companyCell.rent() + "$.</i>"
                        + "</html>"), c);

                JButton okbttn = new JButton("OK");
                okbttn.setAlignmentX(JComponent.CENTER_ALIGNMENT);
                okbttn.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        _canPlayerPaidRent = false;

                        GameViewEvent event = new GameViewEvent(this, p,
                                companyCell);
                        fireMadePlayerPayRent(event);

                        infoDialog.dispose();
                    }
                });

                c.fill = GridBagConstraints.NONE;
                c.gridy = 1;
                infoDialog.add(okbttn, c);

                infoDialog.pack();
                infoDialog.setLocationRelativeTo(this);
                infoDialog.setResizable(false);
                infoDialog.setVisible(true);

                if (_canPlayerPaidRent == true) {
                    final Dialog dialog = new JDialog();
                    dialog.setModal(true);
                    dialog.setTitle("Игрок \"" + p.name() + "\"");
                    dialog.setLayout(new GridBagLayout());

                    c = new GridBagConstraints();
                    c.fill = GridBagConstraints.BOTH;
                    c.insets = new Insets(5, 5, 5, 5);

                    final JLabel questionLbl = new JLabel();
                    final JLabel amountLbl = new JLabel();
                    final JSpinner amountSpr = new JSpinner();
                    final JButton ybttn = new JButton("Да");
                    ybttn.setAlignmentX(JComponent.CENTER_ALIGNMENT);
                    final JButton nbttn = new JButton("Нет");
                    nbttn.setAlignmentX(JComponent.CENTER_ALIGNMENT);

                    c.gridx = 0;
                    c.gridy = 0;
                    dialog.add(questionLbl, c);

                    c.gridx = 0;
                    c.gridy = 1;
                    dialog.add(amountLbl, c);

                    c.gridx = 0;
                    c.gridy = 2;
                    dialog.add(amountSpr, c);

                    c.gridx = 0;
                    c.gridy = 3;
                    c.fill = GridBagConstraints.NONE;
                    dialog.add(ybttn, c);

                    c.gridx = 0;
                    c.gridy = 4;
                    dialog.add(nbttn, c);

                    questionLbl.setText("<html>"
                            + "Желаете попробывать перекупить у игрока <font color="
                            + HTMLColors.getName(color) + ">\"" + owner.name()
                            + "\"</font> фирму <u>\"" + companyCell.name()
                            + "\"</u>?"
                            + "</html>");

                    amountLbl.setText("Предложить сумму ($):");

                    SpinnerModel sprModel = new SpinnerNumberModel(
                            companyCell.cost(), companyCell.cost(),
                            companyCell.cost() * 10, 1000);
                    amountSpr.setModel(sprModel);

                    ybttn.setActionCommand("P1");
                    ybttn.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            String actionCommand = e.getActionCommand();
                            if ("P1".equals(actionCommand)) {
                                dialog.setTitle("Игрок \"" + owner.name() + "\"");

                                questionLbl.setText("<html>"
                                        + "Игрок <font color="
                                        + HTMLColors.getName(p.color()) + ">\""
                                        + p.name() + "\"</font> предложил вам "
                                        + "продать свою фирму <u>\""
                                        + companyCell.name() + "\"</u>. Вы согласны?"
                                        + "</html>");
                                amountLbl.setText("Предложенная сумма ($):");

                                amountSpr.setEnabled(false);

                                ybttn.setActionCommand("P2");

                                dialog.pack();
                            } else if ("P2".equals(actionCommand)) {
                                _canPlayerBuyLand = false;
                                GameViewEvent event = new GameViewEvent(this, p,
                                        companyCell, (Integer) amountSpr.getValue());
                                fireMadePlayerBuyLand(event);

                                dialog.dispose();
                            }
                        }
                    });

                    nbttn.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            _canPlayerBuyLand = true;
                            dialog.dispose();
                        }
                    });

                    dialog.pack();
                    dialog.setLocationRelativeTo(this);
                    dialog.setResizable(false);
                    dialog.setVisible(true);

                    if (_canPlayerBuyLand == false) {
                        showSimpleDialogMessage("Недостаточно денежных средств",
                                "<html>"
                                + "Игроку <font color=" + HTMLColors.getName(p.color())
View Full Code Here

     */
    public void gamePlayerLandsConfiscated(GameModelEvent e) {
        Player p = e.getPlayer();
        List<ILand> confiscated = e.getConfiscated();

        final Dialog infoDialog = new JDialog();
        infoDialog.setModal(true);
        infoDialog.setTitle("Конфискация фирм");
        infoDialog.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.BOTH;
        c.insets = new Insets(5, 5, 5, 5);

        c.gridx = 0;
        c.gridy = 0;
        infoDialog.add(new JLabel("<html>"
                + "У игрока <font color=" + HTMLColors.getName(p.color()) + ">"
                + "\"" + p.name() + "\"</font>" + ", в связи с отсутсвием "
                + "денежных средств для уплаты, были конфискованы следующие "
                + "фирмы: "
                + "</html>"), c);
        List<String> companyNames = new ArrayList<String>();
        for (ILand company : confiscated) {
            companyNames.add(company.name());
        }

        JList list = new JList(companyNames.toArray());
        list.setLayoutOrientation(JList.VERTICAL);
        list.setVisibleRowCount(0);

        JScrollPane scroll = new JScrollPane(list);
        scroll.setPreferredSize(new Dimension(100, 100));

        c.gridy = 1;
        infoDialog.add(scroll, c);

        JButton bttn = new JButton("OK");
        bttn.setAlignmentX(JComponent.CENTER_ALIGNMENT);
        bttn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                infoDialog.dispose();
            }
        });

        c.fill = GridBagConstraints.NONE;
        c.gridy = 2;
        infoDialog.add(bttn, c);

        infoDialog.pack();
        infoDialog.setLocationRelativeTo(this);
        infoDialog.setResizable(false);
        infoDialog.setVisible(true);
    }
View Full Code Here

                + "Игрок <font color=" + HTMLColors.getName(p.color()) + ">"
                + "\"" + p.name() + "\"</font> стал монополистом и победил в игре."
                + "</html>");

        final JFrame mainWindow = this;
        final Dialog infoDialog = new JDialog();
        infoDialog.setModal(true);
        infoDialog.setTitle("Новая игра");
        infoDialog.setLayout(new GridBagLayout());

        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.BOTH;
        c.insets = new Insets(5, 5, 5, 5);

        c.gridx = 0;
        c.gridy = 0;
        infoDialog.add(new JLabel("Начать новую игру?"), c);

        JButton ybttn = new JButton("Да");
        ybttn.setAlignmentX(JComponent.CENTER_ALIGNMENT);
        ybttn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                startNewGame();
                infoDialog.dispose();
            }
        });

        c.fill = GridBagConstraints.NONE;
        c.gridy = 1;
        infoDialog.add(ybttn, c);

        JButton nbttn = new JButton("Нет");
        nbttn.setAlignmentX(JComponent.CENTER_ALIGNMENT);
        nbttn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                infoDialog.dispose();

                mainWindow.setVisible(false);
                mainWindow.dispose();
            }
        });

        c.gridy = 2;
        infoDialog.add(nbttn, c);

        infoDialog.pack();
        infoDialog.setLocationRelativeTo(this);
        infoDialog.setResizable(false);
        infoDialog.setVisible(true);
    }
View Full Code Here

        /**
         * Показать подробную информацию о игроке.
         */
        public void showPlayerInfo() {
            final Dialog infoDialog = new JDialog();
            infoDialog.setModal(true);
            infoDialog.setTitle(_player.name());
            infoDialog.setLayout(new GridBagLayout());

            GridBagConstraints c = new GridBagConstraints();
            c.fill = GridBagConstraints.BOTH;
            c.insets = new Insets(5, 5, 5, 5);
            c.ipady = 5;
            c.ipadx = 5;

            c.gridx = 0;
            c.gridy = 0;
            infoDialog.add(new JLabel("<html>"
                    + "Имя игрока: <font color="
                    + HTMLColors.getName(_player.color()) + ">"
                    + _player.name() + "</font>"
                    + "</html>"), c);

            c.gridy = 1;
            infoDialog.add(new JLabel("<html>"
                    + "Обладает капиталом: <i>"
                    + _player.capital() + "$</i>"
                    + "</html>"), c);

            c.gridy = 2;
            infoDialog.add(new JLabel("<html>"
                    + "Обладает денежной суммой: <i>"
                    + _player.money() + "$</i>"
                    + "</html>"), c);

            c.gridy = 3;
            c.ipady = 0;
            c.ipadx = 0;
            infoDialog.add(new JLabel("Владеет следующими фирмами: "), c);

            List<String> companyNames = new ArrayList<String>();
            for (ILand company : _player.landowning()) {
                companyNames.add(company.name());
            }

            JList list = new JList(companyNames.toArray());
            list.setLayoutOrientation(JList.VERTICAL);
            list.setVisibleRowCount(0);

            JScrollPane scroll = new JScrollPane(list);
            scroll.setPreferredSize(new Dimension(100, 100));

            c.gridy = 4;
            c.ipady = 5;
            c.ipadx = 5;
            infoDialog.add(scroll, c);

            JButton bttn = new JButton("OK");
            bttn.setAlignmentX(JComponent.CENTER_ALIGNMENT);
            bttn.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    infoDialog.dispose();
                }
            });

            c.fill = GridBagConstraints.NONE;
            c.gridy = 6;
            c.ipady = 0;
            c.ipadx = 0;
            infoDialog.add(bttn, c);

            infoDialog.pack();
            infoDialog.setLocationRelativeTo(this);
            infoDialog.setResizable(false);
            infoDialog.setVisible(true);
        }
View Full Code Here

TOP

Related Classes of java.awt.Dialog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.