Exemplo n.º 1
0
  public PlayerWaitingView() {

    this.setOpaque(true);
    this.setLayout(new BorderLayout());
    this.setBorder(BorderFactory.createLineBorder(Color.black, BORDER_WIDTH));

    // set the heading at the top of the pane
    label = new JLabel("Player Waiting View");
    FontUtils.setFont(label, LABEL_TEXT_SIZE);
    this.add(label, BorderLayout.NORTH);

    // create the center panel that displays player info
    center = new JPanel();
    center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
    this.add(center, BorderLayout.CENTER);

    // create the AI panel for the bottom of the pane
    aiPanel = new JPanel();
    aiPanel.setLayout(new BoxLayout(aiPanel, BoxLayout.Y_AXIS));

    // create the AI type panel
    JPanel aiTypePanel = new JPanel();
    aiTypePanel.setLayout(new BoxLayout(aiTypePanel, BoxLayout.X_AXIS));

    aiTypePanel.add(Box.createHorizontalGlue());

    JLabel aiTypeLabel = new JLabel("Select AI Type:");
    FontUtils.setFont(aiTypeLabel, AI_TEXT_SIZE);
    aiTypePanel.add(aiTypeLabel);

    aiTypePanel.add(Box.createRigidArea(new Dimension(5, 0)));

    aiModel = new SpinnerListModel();
    aiChoices = new JSpinner(aiModel);
    ((JSpinner.DefaultEditor) aiChoices.getEditor()).getTextField().setEditable(false);
    FontUtils.setFont(aiChoices, AI_TEXT_SIZE);
    aiTypePanel.add(aiChoices);

    aiTypePanel.add(Box.createHorizontalGlue());

    aiPanel.add(aiTypePanel);

    aiPanel.add(Box.createRigidArea(new Dimension(0, 10)));

    // create the AI button panel
    JPanel aiButtonPanel = new JPanel();
    aiButtonPanel.setLayout(new BoxLayout(aiButtonPanel, BoxLayout.X_AXIS));

    aiButtonPanel.add(Box.createHorizontalGlue());

    addAiButton = new JButton("Add a computer player");
    addAiButton.addActionListener(actionListener);
    FontUtils.setFont(addAiButton, BUTTON_TEXT_SIZE);
    aiButtonPanel.add(addAiButton);

    aiButtonPanel.add(Box.createHorizontalGlue());

    aiPanel.add(aiButtonPanel);

    aiPanel.add(Box.createRigidArea(new Dimension(0, 10)));

    // add the AI panel
    this.add(aiPanel, BorderLayout.SOUTH);
  }
Exemplo n.º 2
0
  public GUI() {

    // Frame
    frame = new JFrame("HardwareSwap Notifier");

    // Panels
    panel = new JPanel();
    group1 = new JPanel();
    group2 = new JPanel();
    group3 = new JPanel();
    group4 = new JPanel();
    group5 = new JPanel();
    group6 = new JPanel();
    group7 = new JPanel();
    group8 = new JPanel();

    // Menu Bar
    menus = new JMenuBar();
    fileMenu = new JMenu("File");
    clearCurrent = new JMenuItem("Clear");
    quitItem = new JMenuItem("Quit");
    load = new JMenuItem("Load");
    saveCurrent = new JMenuItem("Save All");
    clearSaved = new JMenuItem("Clear Saved");
    removeItem = new JMenuItem("Remove Item");
    removePhone = new JMenuItem("Remove Phone");
    saveCurrent = new JMenuItem("Save Current");
    helpMenu = new JMenu("Help");
    help = new JMenuItem("How To Use");
    about = new JMenuItem("About");

    // Buttons
    add1 = new JButton("Add");
    add2 = new JButton("Add");
    start = new JButton("Start");
    stop = new JButton("Stop");
    save1 = new JButton("Add/Save");
    save2 = new JButton("Add/Save");
    show = new JButton("Display Data");

    add1.setFocusPainted(false);
    add2.setFocusPainted(false);
    start.setFocusPainted(false);
    stop.setFocusPainted(false);
    save1.setFocusPainted(false);
    save2.setFocusPainted(false);
    show.setFocusPainted(false);

    stop.setEnabled(false);

    // CheckBox
    remove = new JCheckBox("Remove items when found");
    remove.setFocusable(false);

    // Listener
    ButtonListener listener = new ButtonListener();

    add1.addActionListener(listener);
    add2.addActionListener(listener);
    start.addActionListener(listener);
    stop.addActionListener(listener);
    load.addActionListener(listener);
    save1.addActionListener(listener);
    save2.addActionListener(listener);
    saveCurrent.addActionListener(listener);
    show.addActionListener(listener);
    quitItem.addActionListener(listener);
    clearCurrent.addActionListener(listener);
    clearSaved.addActionListener(listener);
    saveCurrent.addActionListener(listener);
    help.addActionListener(listener);
    about.addActionListener(listener);
    removePhone.addActionListener(listener);
    removeItem.addActionListener(listener);
    remove.addActionListener(listener);

    // Carrier Selection
    options = new String[10];
    options[0] = "AT&T";
    options[1] = "Boost Mobile";
    options[2] = "Cellular One";
    options[3] = "Nextel";
    options[4] = "T-Mobile";
    options[5] = "Tracfone";
    options[6] = "US Cellular";
    options[7] = "Sprint";
    options[8] = "Verizon";
    options[9] = "Virgin Mobile";

    carriers = new JComboBox<String>(options);

    // Text Fields
    searchName = new JTextField(15);
    item = new JTextField(15);
    phone = new JTextField(15);
    interval2 = new JTextField(15);
    results = new JTextArea(10, 20);

    JScrollPane scrollPane = new JScrollPane(results);

    results.setEditable(false);

    // Interval
    intOptions = new SpinnerNumberModel(5, 1, 60, 1);
    interval = new JSpinner(intOptions);
    JFormattedTextField tf = ((JSpinner.DefaultEditor) interval.getEditor()).getTextField();
    tf.setHorizontalAlignment(JFormattedTextField.LEFT);

    // Background
    panelBackground = new Color(237, 237, 237);

    panel.setBackground(panelBackground);
    searchName.setBackground(panelBackground);
    item.setBackground(panelBackground);
    phone.setBackground(panelBackground);
    interval.setBackground(panelBackground);

    // Panel Layouts
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    group1.setLayout(new BoxLayout(group1, BoxLayout.PAGE_AXIS));
    group2.setLayout(new BoxLayout(group2, BoxLayout.X_AXIS));
    group3.setLayout(new BoxLayout(group3, BoxLayout.PAGE_AXIS));
    group4.setLayout(new BoxLayout(group4, BoxLayout.X_AXIS));
    group5.setLayout(new BoxLayout(group5, BoxLayout.X_AXIS));
    group6.setLayout(new BoxLayout(group6, BoxLayout.X_AXIS));
    group7.setLayout(new BoxLayout(group7, BoxLayout.X_AXIS));
    group8.setLayout(new BoxLayout(group8, BoxLayout.X_AXIS));

    // Borders
    searchName.setBorder(
        BorderFactory.createTitledBorder(
            null,
            "Search Name",
            TitledBorder.DEFAULT_JUSTIFICATION,
            TitledBorder.DEFAULT_JUSTIFICATION,
            null,
            Color.DARK_GRAY));
    item.setBorder(
        BorderFactory.createTitledBorder(
            null,
            "Item",
            TitledBorder.DEFAULT_JUSTIFICATION,
            TitledBorder.DEFAULT_JUSTIFICATION,
            null,
            Color.DARK_GRAY));
    phone.setBorder(
        BorderFactory.createTitledBorder(
            null,
            "Cell Phone",
            TitledBorder.DEFAULT_JUSTIFICATION,
            TitledBorder.DEFAULT_JUSTIFICATION,
            null,
            Color.DARK_GRAY));
    group5.setBorder(
        BorderFactory.createTitledBorder(
            null,
            "Check Interval (mins)",
            TitledBorder.DEFAULT_JUSTIFICATION,
            TitledBorder.DEFAULT_JUSTIFICATION,
            null,
            Color.DARK_GRAY));

    // Sizes
    panel.setPreferredSize(new Dimension(200, 0));
    searchName.setMaximumSize(new Dimension(190, 50));
    item.setMaximumSize(new Dimension(190, 50));
    phone.setMaximumSize(new Dimension(185, 50));
    carriers.setMaximumSize(new Dimension(175, 20));
    group5.setPreferredSize(new Dimension(190, 47));
    group5.setMaximumSize(new Dimension(190, 47));

    add1.setMaximumSize(new Dimension(90, 20));
    save1.setMaximumSize(new Dimension(90, 20));
    add2.setMaximumSize(new Dimension(90, 20));
    save2.setMaximumSize(new Dimension(90, 20));
    start.setMaximumSize(new Dimension(90, 20));
    stop.setMaximumSize(new Dimension(90, 20));
    show.setMaximumSize(new Dimension(120, 20));

    // Add file menu items
    fileMenu.add(clearCurrent);
    fileMenu.add(clearSaved);
    fileMenu.add(load);
    fileMenu.add(removeItem);
    fileMenu.add(removePhone);
    fileMenu.add(saveCurrent);
    fileMenu.add(quitItem);

    // Add help menu items
    helpMenu.add(help);
    helpMenu.add(about);

    // Add to menu bar
    menus.add(fileMenu);
    menus.add(helpMenu);

    // Add items to panel
    group1.add(searchName);
    group1.add(item);

    group2.add(add1);
    group2.add(Box.createHorizontalStrut(10));
    group2.add(save1);

    group6.add(remove);

    group3.add(phone);
    group3.add(Box.createVerticalStrut(10));
    group3.add(carriers);

    group4.add(add2);
    group4.add(Box.createHorizontalStrut(10));
    group4.add(save2);

    group5.add(interval);

    group7.add(show);

    group8.add(start);
    group8.add(Box.createHorizontalStrut(10));
    group8.add(stop);

    panel.add(Box.createVerticalStrut(10));
    panel.add(group1);
    panel.add(Box.createVerticalStrut(10));
    panel.add(group2);
    panel.add(Box.createVerticalStrut(40));
    panel.add(group3);
    panel.add(Box.createVerticalStrut(10));
    panel.add(group4);
    panel.add(Box.createVerticalStrut(40));
    panel.add(group5);
    panel.add(Box.createVerticalStrut(30));
    panel.add(group6);
    panel.add(Box.createVerticalStrut(40));
    panel.add(group7);
    panel.add(Box.createVerticalStrut(10));
    panel.add(group8);
    panel.add(Box.createVerticalStrut(10));

    // Setup frame
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(menus);
    frame.add(scrollPane);
    frame.add(BorderLayout.EAST, panel);
    frame.pack();
    frame.setSize(new Dimension(670, 620));
    frame.setVisible(true);
  }
Exemplo n.º 3
0
    public NumberField(NumberOption option) {
      super(option);

      panel = new JPanel(new GridBagLayout());
      this.step = option.getStep();
      Double min = option.getMin();
      Double max = option.getMax();
      Double defl = new Double(option.getDefault());

      // Normalize parameters
      if (min != null && defl.compareTo(min) < 0) {
        defl = min;
      } else if (max != null && defl.compareTo(max) > 0) {
        defl = max;
      }
      if (min != null) {
        sliderMin = (int) (min.doubleValue() / step);
      } else {
        sliderMin = SLIDER_DEFAULT_MIN;
      }
      if (max != null) {
        sliderMax = (int) (max.doubleValue() / step);
      } else {
        sliderMax = SLIDER_DEFAULT_MAX;
      }

      // Create spinner
      SpinnerNumberModel spinnerModel = new SpinnerNumberModel(defl, min, max, new Double(step));
      spinner = new JSpinner(spinnerModel);
      ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setColumns(FIELD_WIDTH);

      // Create slider
      slider = new JSlider(sliderMin, sliderMax, sliderIndex(defl));
      slider.setPaintLabels(false);
      slider.setPaintTicks(false);
      slider.setSnapToTicks(false);

      // Add listeners.  The spinner is the master and the slider is
      // the slave.
      spinner.addChangeListener(
          new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
              int newIndex = sliderIndex((Double) spinner.getValue());
              if (slider.getValue() != newIndex) {
                slider.setValue(newIndex);
              }
              fireChangeEvent();
            }
          });
      slider.addChangeListener(
          new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
              int newIndex = slider.getValue();
              if (newIndex != sliderIndex((Double) spinner.getValue())) {
                spinner.setValue(new Double(newIndex * step));
              }
            }
          });

      // Create enable checkbox
      configureEnableToggle(
          option.isInitiallyEnabled(),
          string(option.getDisabledValue()),
          Arrays.asList((JComponent) spinner, slider));

      // Add to the panel
      panel.add(spinner);
      GridBagConstraints c = new GridBagConstraints();
      c.insets = new Insets(0, 8, 0, 0);
      c.fill = GridBagConstraints.HORIZONTAL;
      c.weightx = 1;
      panel.add(slider, c);
    }