/**
   * Create the pixel location panel
   *
   * @param labelFont the font for the labels
   * @return the location panel
   */
  public JPanel createLocationPanel(Font labelFont) {

    // create a location panel
    JPanel locationPanel = new JPanel();
    locationPanel.setLayout(new FlowLayout());
    Box hBox = Box.createHorizontalBox();

    // create the labels
    rowLabel = new JLabel("Row:");
    colLabel = new JLabel("Column:");

    // create the text fields
    colValue = new JTextField(Integer.toString(colIndex + numberBase), 6);
    colValue.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            displayPixelInformation(colValue.getText(), rowValue.getText());
          }
        });
    rowValue = new JTextField(Integer.toString(rowIndex + numberBase), 6);
    rowValue.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            displayPixelInformation(colValue.getText(), rowValue.getText());
          }
        });

    // set up the next and previous buttons
    setUpNextAndPreviousButtons();

    // set up the font for the labels
    colLabel.setFont(labelFont);
    rowLabel.setFont(labelFont);
    colValue.setFont(labelFont);
    rowValue.setFont(labelFont);

    // add the items to the vertical box and the box to the panel
    hBox.add(Box.createHorizontalGlue());
    hBox.add(rowLabel);
    hBox.add(rowPrevButton);
    hBox.add(rowValue);
    hBox.add(rowNextButton);
    hBox.add(Box.createHorizontalStrut(10));
    hBox.add(colLabel);
    hBox.add(colPrevButton);
    hBox.add(colValue);
    hBox.add(colNextButton);
    locationPanel.add(hBox);
    hBox.add(Box.createHorizontalGlue());

    return locationPanel;
  }
예제 #2
0
  @Override
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    textLabel.setFont(table.getFont());
    textLabel.setText(Objects.toString(value, ""));
    textLabel.setBorder(hasFocus ? focusCellHighlightBorder : noFocusBorder);

    FontMetrics fm = table.getFontMetrics(table.getFont());
    Insets i = textLabel.getInsets();
    int swidth =
        iconLabel.getPreferredSize().width + fm.stringWidth(textLabel.getText()) + i.left + i.right;
    int cwidth = table.getColumnModel().getColumn(column).getWidth();
    dim.width = swidth > cwidth ? cwidth : swidth;

    if (isSelected) {
      textLabel.setOpaque(true);
      textLabel.setForeground(table.getSelectionForeground());
      textLabel.setBackground(table.getSelectionBackground());
      iconLabel.setIcon(sicon);
    } else {
      textLabel.setOpaque(false);
      textLabel.setForeground(table.getForeground());
      textLabel.setBackground(table.getBackground());
      iconLabel.setIcon(nicon);
    }
    return panel;
  }
    public SidebarOption(String labelTxt, String rsc) {
      label = new JLabel(labelTxt);
      label.setForeground(Color.WHITE);
      label.setFont(font);
      add(label);
      setOpaque(false);
      setMaximumSize(new Dimension(1000, label.getPreferredSize().height + 5));

      this.rsc = ClassLoader.getSystemClassLoader().getResource(rsc);
    }
  /**
   * Create the color information panel
   *
   * @param labelFont the font to use for labels
   * @return the color information panel
   */
  private JPanel createColorInfoPanel(Font labelFont) {
    // create a color info panel
    JPanel colorInfoPanel = new JPanel();
    colorInfoPanel.setLayout(new FlowLayout());

    // get the pixel at the x and y
    Pixel pixel = new Pixel(picture, colIndex, rowIndex);

    // create the labels
    rValue = new JLabel("R: " + pixel.getRed());
    gValue = new JLabel("G: " + pixel.getGreen());
    bValue = new JLabel("B: " + pixel.getBlue());

    // create the sample color panel and label
    colorLabel = new JLabel("Color at location: ");
    colorPanel = new JPanel();
    colorPanel.setBorder(new LineBorder(Color.black, 1));

    // set the color sample to the pixel color
    colorPanel.setBackground(pixel.getColor());

    // set the font
    rValue.setFont(labelFont);
    gValue.setFont(labelFont);
    bValue.setFont(labelFont);
    colorLabel.setFont(labelFont);
    colorPanel.setPreferredSize(new Dimension(25, 25));

    // add items to the color information panel
    colorInfoPanel.add(rValue);
    colorInfoPanel.add(gValue);
    colorInfoPanel.add(bValue);
    colorInfoPanel.add(colorLabel);
    colorInfoPanel.add(colorPanel);

    return colorInfoPanel;
  }
예제 #5
0
  /** Init visible components. */
  private void init() {
    TransparentPanel panel = new TransparentPanel(new BorderLayout());

    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    // Title label
    JLabel titleLabel =
        new JLabel(GuiActivator.getResources().getI18NString("service.gui.avatar.RECENT_ICONS"));
    titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD));

    // fix for displaying text in menu
    // when using a dark OS theme (as default one in ubuntu)
    titleLabel.setForeground(new JMenuItem().getForeground());

    panel.add(titleLabel, BorderLayout.NORTH);

    // Init recent images grid
    TransparentPanel recentImagesGrid = new TransparentPanel();
    recentImagesGrid.setLayout(new GridLayout(0, IMAGES_PER_COLUMN));

    Dimension thumbsize = new Dimension(THUMB_WIDTH, THUMB_HEIGHT);
    for (int i = 0; i < MAX_STORED_IMAGES; i++) {
      this.recentImagesButtons[i] = new SIPCommButton(null);
      this.recentImagesButtons[i].setBorder(BorderFactory.createEtchedBorder());
      this.recentImagesButtons[i].setMaximumSize(thumbsize);
      this.recentImagesButtons[i].setMinimumSize(thumbsize);
      this.recentImagesButtons[i].setPreferredSize(thumbsize);
      this.recentImagesButtons[i].addActionListener(this);
      this.recentImagesButtons[i].setName("" + i);
      recentImagesGrid.add(this.recentImagesButtons[i]);
    }

    panel.add(recentImagesGrid, BorderLayout.CENTER);

    // Action buttons
    TransparentPanel buttonsPanel = new TransparentPanel();
    buttonsPanel.setLayout(new GridLayout(0, 1));

    // we use this menu item just to get its foreground color.
    Color linkColor = new JMenuItem().getForeground();

    addActionButton(
        buttonsPanel,
        this,
        GuiActivator.getResources().getI18NString("service.gui.avatar.CHOOSE_ICON"),
        CHOSE_BUTTON_NAME,
        linkColor);
    addActionButton(
        buttonsPanel,
        this,
        GuiActivator.getResources().getI18NString("service.gui.avatar.REMOVE_ICON"),
        REMOVE_BUTTON_NAME,
        linkColor);
    addActionButton(
        buttonsPanel,
        this,
        GuiActivator.getResources().getI18NString("service.gui.avatar.CLEAR_RECENT"),
        CLEAR_BUTTON_NAME,
        linkColor);

    panel.add(buttonsPanel, BorderLayout.SOUTH);

    this.setLayout(new BorderLayout());
    this.add(panel, BorderLayout.CENTER);
  }
예제 #6
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
  public LJ3MDApp() {
    tNum.setHorizontalAlignment(JTextField.CENTER);
    tTemp.setHorizontalAlignment(JTextField.CENTER);
    tRho.setHorizontalAlignment(JTextField.CENTER);
    tSpeed.setHorizontalAlignment(JTextField.CENTER);

    tAvK.setHorizontalAlignment(JTextField.RIGHT);
    tAvU.setHorizontalAlignment(JTextField.RIGHT);
    tAvp.setHorizontalAlignment(JTextField.RIGHT);

    float[] aveKing = new float[501];
    float[] avePot = new float[501];
    float[] aveEn = new float[501];

    JFrame box = new JFrame();
    box.setLayout(new BorderLayout());
    box.setSize(1000, 1000);
    box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    cpnl = new JPanel(); // create a panel for controls
    cpnl.setLayout(new GridLayout(18, 2));
    box.add(cpnl, BorderLayout.EAST);

    // add controls
    cpnl.add(bStart);
    bStart.addActionListener(this);

    cpnl.add(bReset);
    bReset.addActionListener(this);

    cpnl.add(new JLabel(" N:"));
    tNum.addActionListener(this);
    cpnl.add(tNum);

    cpnl.add(new JLabel(" Density (\u03c1):"));
    tRho.addActionListener(this);
    cpnl.add(tRho);

    cpnl.add(new JLabel(" Steps/frame:"));
    tSpeed.addActionListener(this);
    cpnl.add(tSpeed);

    cpnl.add(bTstat);
    bTstat.addActionListener(this);

    cpnl.add(bPot);
    bPot.addActionListener(this);

    cpnl.add(new JLabel(" < K/N > :"));
    tAvK.setEditable(false);
    cpnl.add(tAvK);

    cpnl.add(new JLabel(" Temperature:"));
    tTemp.setEditable(false);
    cpnl.add(tTemp);

    cpnl.add(new JLabel(" < U/N > :"));
    tAvU.setEditable(false);
    cpnl.add(tAvU);

    cpnl.add(new JLabel(" < pressure > :"));
    tAvp.setEditable(false);
    cpnl.add(tAvp);

    cpnl.add(bRetime);
    bRetime.addActionListener(this);

    spnl = new JPanel(); // create a panel for status
    box.add(spnl, BorderLayout.SOUTH);
    lStatus.setFont(new Font("Courier", 0, 12));
    spnl.add(lStatus);

    canvas = new XYZCanvas();
    box.add(canvas, BorderLayout.CENTER);

    timer = new Timer(delay, this);
    timer.start();
    //        timer.stop();
    box.setVisible(true);
  }
예제 #7
0
파일: TicTac.java 프로젝트: Sykess/Eastwood
  /** Constructor to set everything up */
  public TicTac() {
    // Set defaults before settings are changed via menus
    // (defaults are vs AI, play as X, with graphics on)
    multiPlayers = false;
    temp = false;
    currentPlayer = Symbol.X;
    ai = Symbol.O;
    difficulty = Difficulty.IMPOSSIBLE;

    frame = new JFrame("Tic Tac Toe");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    // Set preferred size so game fills window nicely
    this.setPreferredSize(new Dimension(cellSize * ROWS, cellSize * COLS));
    frame.add(this);

    // Load images
    try {
      sword = ImageIO.read(new File("swordsBlue.png"));
      saber = ImageIO.read(new File("saber2.png"));
      skull = ImageIO.read(new File("skull.png"));
      ring = ImageIO.read(new File("ring.png"));
      smiley = ImageIO.read(new File("smiley.png"));
      hydra = ImageIO.read(new File("hydra.png"));
      finalfantasy = ImageIO.read(new File("finalfantasy.jpg"));
      dragon = ImageIO.read(new File("dargon.jpg"));
      night = ImageIO.read(new File("night.jpg"));
    } catch (IOException e) {
      System.out.println("Could not open image files, turning images off!");
      useImages = false;
    }

    imageX = saber;
    imageO = ring;
    background = dragon;

    // Create menu bars.  Each one item will need a listener
    menuBar = new JMenuBar();
    JMenu menu = new JMenu("Mode");
    JMenu menu2 = new JMenu("Side");
    JMenu menu3 = new JMenu("Graphics");
    JMenu menu4 = new JMenu("Other");
    JMenu menu5 = new JMenu("Difficulty");
    JMenu xImageMenu = new JMenu("Image for X");
    JMenu oImageMenu = new JMenu("Image for O");
    JMenu backgroundMenu = new JMenu("Set Background");
    menuBar.add(menu);
    menuBar.add(menu2);
    menuBar.add(menu5);
    menuBar.add(menu3);
    menuBar.add(menu4);

    // Create checkbox menu items for choices
    final JCheckBoxMenuItem item = new JCheckBoxMenuItem("2 Player");
    final JCheckBoxMenuItem item2 = new JCheckBoxMenuItem("VS Computer");
    final JCheckBoxMenuItem item3 = new JCheckBoxMenuItem("Play as X");
    final JCheckBoxMenuItem item4 = new JCheckBoxMenuItem("Play as O");
    final JCheckBoxMenuItem item5 = new JCheckBoxMenuItem("On");
    final JCheckBoxMenuItem item6 = new JCheckBoxMenuItem("Off");
    JMenuItem item7 = new JMenuItem("Restart");
    JMenuItem item8 = new JMenuItem("Exit");
    final JCheckBoxMenuItem item9 = new JCheckBoxMenuItem("Easy");
    final JCheckBoxMenuItem item10 = new JCheckBoxMenuItem("Hard");
    final JCheckBoxMenuItem item11 = new JCheckBoxMenuItem("Impossible");
    final JCheckBoxMenuItem itemSword = new JCheckBoxMenuItem("Sword");
    final JCheckBoxMenuItem itemSaber = new JCheckBoxMenuItem("Sabers");
    final JCheckBoxMenuItem itemSkull = new JCheckBoxMenuItem("Skull");
    final JCheckBoxMenuItem itemRing = new JCheckBoxMenuItem("One Ring");
    final JCheckBoxMenuItem itemSmiley = new JCheckBoxMenuItem("Red Smiley");
    final JCheckBoxMenuItem itemHydra = new JCheckBoxMenuItem("Hydra");
    final JCheckBoxMenuItem itemDragon = new JCheckBoxMenuItem("Dragon");
    final JCheckBoxMenuItem itemFinalFantasy = new JCheckBoxMenuItem("Final Fantasy 7");
    final JCheckBoxMenuItem itemNight = new JCheckBoxMenuItem("Nighttime");

    // Set the initial checkboxes to true (for play vs ai, as X, with graphics on)
    item2.setSelected(true);
    item3.setSelected(true);
    item5.setSelected(true);
    item11.setSelected(true);
    itemSaber.setSelected(true);
    itemRing.setSelected(true);
    itemDragon.setSelected(true);

    // Play against friend
    item.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            item.setSelected(true);
            item2.setSelected(false);
            multiPlayers = true;
            repaint();
          }
        });
    menu.add(item);

    // Checkbox for Selecting to play against AI
    item2.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            item2.setSelected(true);
            item.setSelected(false);
            if (currentPlayer == Symbol.X) ai = Symbol.O;
            else ai = Symbol.X;
            item3.setSelected(true);
            item4.setSelected(false);
            multiPlayers = false;
          }
        });
    menu.add(item2);

    // Play as X
    item3.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            // use temp variable to move after assigning symbols
            if (item4.getState() && !multiPlayers) temp = true;
            item3.setSelected(true);
            item4.setSelected(false);
            currentPlayer = Symbol.X;
            ai = Symbol.O;
            if (temp) aiMove();
            repaint();
            temp = false;
          }
        });
    menu2.add(item3);

    // Play as O
    item4.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (item3.getState() && !multiPlayers) temp = true;
            item4.setSelected(true);
            item3.setSelected(false);
            currentPlayer = Symbol.O;
            ai = Symbol.X;
            if (temp) aiMove();
            repaint();
            temp = false;
          }
        });
    menu2.add(item4);

    // Turn Graphics on
    item5.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            item5.setSelected(true);
            item6.setSelected(false);
            useImages = true;
            repaint();
          }
        });
    menu3.add(item5);

    // Turn Graphics off
    item6.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            item5.setSelected(false);
            item6.setSelected(true);
            useImages = false;
            repaint();
          }
        });
    menu3.add(item6);
    menu3.addSeparator();
    menu3.add(xImageMenu);
    menu3.add(oImageMenu);
    menu3.add(backgroundMenu);

    // Choose Saber for X
    itemSaber.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemSword.setSelected(false);
            itemSaber.setSelected(true);
            itemSkull.setSelected(false);
            imageX = saber;
            repaint();
          }
        });
    xImageMenu.add(itemSaber);

    // Choose Sword for X
    itemSword.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemSword.setSelected(true);
            itemSaber.setSelected(false);
            itemSkull.setSelected(false);
            imageX = sword;
            repaint();
          }
        });
    xImageMenu.add(itemSword);

    // Choose Skull for X
    itemSkull.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemSword.setSelected(false);
            itemSaber.setSelected(false);
            itemSkull.setSelected(true);
            imageX = skull;
            repaint();
          }
        });
    xImageMenu.add(itemSkull);

    // Choose ring for O
    itemRing.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemRing.setSelected(true);
            itemSmiley.setSelected(false);
            itemHydra.setSelected(false);
            imageO = ring;
            repaint();
          }
        });
    oImageMenu.add(itemRing);

    // Choose red smiley for O
    itemSmiley.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemRing.setSelected(false);
            itemSmiley.setSelected(true);
            itemHydra.setSelected(false);
            imageO = smiley;
            repaint();
          }
        });
    oImageMenu.add(itemSmiley);

    // Choose hydra for O
    itemHydra.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemRing.setSelected(false);
            itemSmiley.setSelected(false);
            itemHydra.setSelected(true);
            imageO = hydra;
            repaint();
          }
        });
    oImageMenu.add(itemHydra);

    // Set dragon as background
    itemDragon.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemDragon.setSelected(true);
            itemFinalFantasy.setSelected(false);
            itemNight.setSelected(false);
            background = dragon;
            repaint();
          }
        });
    backgroundMenu.add(itemDragon);

    // Set final fantasy 7 as background
    itemFinalFantasy.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemDragon.setSelected(false);
            itemFinalFantasy.setSelected(true);
            itemNight.setSelected(false);
            background = finalfantasy;
            repaint();
          }
        });
    backgroundMenu.add(itemFinalFantasy);

    // Set night as background
    itemNight.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemDragon.setSelected(false);
            itemFinalFantasy.setSelected(false);
            itemNight.setSelected(true);
            background = night;
            repaint();
          }
        });
    backgroundMenu.add(itemNight);

    // Reset game
    item7.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            initialize();
          }
        });
    menu4.add(item7);

    // Exit game
    item8.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
    menu4.add(item8);

    // Difficulty easy
    item9.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            difficulty = Difficulty.EASY;
            item9.setSelected(true);
            item10.setSelected(false);
            item11.setSelected(false);
          }
        });
    menu5.add(item9);

    // Difficulty hard
    item10.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            difficulty = Difficulty.HARD;
            item10.setSelected(true);
            item9.setSelected(false);
            item11.setSelected(false);
          }
        });
    menu5.add(item10);

    // Difficulty impossible
    item11.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            difficulty = Difficulty.IMPOSSIBLE;
            item11.setSelected(true);
            item9.setSelected(false);
            item10.setSelected(false);
          }
        });
    menu5.add(item11);

    // Add Whole menu bar to frame
    frame.setJMenuBar(menuBar);

    // Create statusBar (updates will take place in paintComponent)
    statusBar = new JLabel("  ");
    statusBar.setFont(new Font(Font.DIALOG_INPUT, Font.BOLD, 15));
    statusBar.setBorder(BorderFactory.createEmptyBorder(2, 5, 4, 5));
    // Use container variable to set layout and pack everything nicely
    Container cp = frame.getContentPane();
    cp.setLayout(new BorderLayout());
    cp.add(this, BorderLayout.CENTER);
    cp.add(statusBar, BorderLayout.SOUTH);
    frame.pack();

    board = new Symbol[ROWS][COLS];
    initialize();

    // Add the mouse listener.  Use MouseAdapter rather than implement it
    this.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            int currentCol = e.getX() / cellSize;
            int currentRow = e.getY() / cellSize;

            if (gameStatus == GameStatus.CONTINUE) {
              // If valid click, and spot is empty, make the move.  Then check
              // to see if game is won. If not, and facing AI, ai moves.
              // Otherwise switch X and O
              if (currentRow >= 0
                  && currentRow < ROWS
                  && currentCol >= 0
                  && currentCol < COLS
                  && board[currentRow][currentCol] == Symbol.EMPTY) {
                board[currentRow][currentCol] = currentPlayer;
                checkState(currentPlayer);

                if (multiPlayers) currentPlayer = (currentPlayer == Symbol.X) ? Symbol.O : Symbol.X;

                if (gameStatus == GameStatus.CONTINUE && !multiPlayers) aiMove();
              }
            } else {
              // Game is over, so re-initialize everything
              initialize();
            }
            repaint();
          }
        });
  }