Search in sources :

Example 1 with IntTextField

use of games.strategy.ui.IntTextField in project triplea by triplea-game.

the class ClientOptions method initComponents.

private void initComponents() {
    nameField = new JTextField(10);
    addressField = new JTextField(10);
    portField = new IntTextField(0, Integer.MAX_VALUE);
    portField.setColumns(7);
}
Also used : IntTextField(games.strategy.ui.IntTextField) JTextField(javax.swing.JTextField)

Example 2 with IntTextField

use of games.strategy.ui.IntTextField in project triplea by triplea-game.

the class NumberProperty method getEditorComponent.

@Override
public JComponent getEditorComponent() {
    final IntTextField field = new IntTextField(min, max);
    field.setValue(m_value);
    field.addChangeListener(aField -> m_value = aField.getValue());
    return field;
}
Also used : IntTextField(games.strategy.ui.IntTextField)

Example 3 with IntTextField

use of games.strategy.ui.IntTextField in project triplea by triplea-game.

the class ServerOptions method initComponents.

private void initComponents() {
    nameField = new JTextField(10);
    portField = new IntTextField(0, Integer.MAX_VALUE);
    portField.setColumns(7);
    passwordField = new JPasswordField();
    passwordField.setColumns(10);
    comment = new JTextField();
    comment.setColumns(20);
}
Also used : JPasswordField(javax.swing.JPasswordField) IntTextField(games.strategy.ui.IntTextField) JTextField(javax.swing.JTextField)

Example 4 with IntTextField

use of games.strategy.ui.IntTextField in project triplea by triplea-game.

the class GameMenu method addRollDice.

private void addRollDice() {
    final JMenuItem rollDiceBox = new JMenuItem("Roll Dice");
    rollDiceBox.setMnemonic(KeyEvent.VK_R);
    rollDiceBox.addActionListener(e -> {
        final IntTextField numberOfText = new IntTextField(0, 100);
        final IntTextField diceSidesText = new IntTextField(1, 200);
        numberOfText.setText(String.valueOf(0));
        diceSidesText.setText(String.valueOf(gameData.getDiceSides()));
        final JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        panel.add(new JLabel("Number of Dice to Roll: "), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 20), 0, 0));
        panel.add(new JLabel("Sides on the Dice: "), new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 20, 0, 10), 0, 0));
        panel.add(numberOfText, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 20), 0, 0));
        panel.add(diceSidesText, new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 20, 0, 10), 0, 0));
        JOptionPane.showOptionDialog(JOptionPane.getFrameForComponent(this), panel, "Roll Dice", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[] { "OK" }, "OK");
        try {
            final int numberOfDice = Integer.parseInt(numberOfText.getText());
            if (numberOfDice > 0) {
                final int diceSides = Integer.parseInt(diceSidesText.getText());
                final int[] dice = game.getRandomSource().getRandom(diceSides, numberOfDice, "Rolling Dice, no effect on game.");
                final JPanel panelDice = new JPanel();
                final BoxLayout layout = new BoxLayout(panelDice, BoxLayout.Y_AXIS);
                panelDice.setLayout(layout);
                final JLabel label = new JLabel("Rolls (no effect on game): ");
                panelDice.add(label);
                final StringBuilder diceString = new StringBuilder();
                for (int i = 0; i < dice.length; i++) {
                    diceString.append(String.valueOf(dice[i] + 1)).append((i == dice.length - 1) ? "" : ", ");
                }
                final JTextField diceList = new JTextField(diceString.toString());
                diceList.setEditable(false);
                panelDice.add(diceList);
                JOptionPane.showMessageDialog(frame, panelDice, "Dice Rolled", JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (final Exception ex) {
        // ignore malformed input
        }
    });
    add(rollDiceBox);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) IntTextField(games.strategy.ui.IntTextField) JMenuItem(javax.swing.JMenuItem)

Aggregations

IntTextField (games.strategy.ui.IntTextField)4 JTextField (javax.swing.JTextField)3 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 BoxLayout (javax.swing.BoxLayout)1 JLabel (javax.swing.JLabel)1 JMenuItem (javax.swing.JMenuItem)1 JPanel (javax.swing.JPanel)1 JPasswordField (javax.swing.JPasswordField)1