Exemplo n.º 1
0
  public final void initializeGui() {
    // set up the main GUI
    gui.setBorder(new EmptyBorder(5, 5, 5, 5));
    JToolBar tools = new JToolBar();
    tools.setFloatable(false);
    gui.add(tools, BorderLayout.PAGE_START);
    tools.add(new JButton("New")); // TODO - add functionality!
    tools.addSeparator();
    tools.add(new JLabel("Player:")); // TODO - add functionality!
    tools.addSeparator();
    tools.add(message);

    playBoard = new JPanel(new GridLayout(0, 11));
    playBoard.setBorder(new LineBorder(Color.BLACK));
    gui.add(playBoard);

    // create the chess board squares
    Insets buttonMargin = new Insets(0, 0, 0, 0);
    for (int ii = 0; ii < playBoardSquares.length; ii++) {
      for (int jj = 0; jj < playBoardSquares[ii].length; jj++) {
        JButton b = new JButton();
        b.setMargin(buttonMargin);
        // our chess pieces are 64x64 px in size, so we'll
        // 'fill this in' using a transparent icon..
        ImageIcon icon = new ImageIcon(new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB));
        b.setIcon(icon);
        b.setBackground(Color.BLUE);
        playBoardSquares[jj][ii] = b;
      }
    }

    // fill the chess board
    playBoard.add(new JLabel(""));
    // fill the top row
    for (int ii = 0; ii < 10; ii++) {
      playBoard.add(new JLabel(COLS.substring(ii, ii + 1), SwingConstants.CENTER));
    }
    // fill the black non-pawn piece row
    for (int ii = 0; ii < 10; ii++) {
      for (int jj = 0; jj < 10; jj++) {
        switch (jj) {
          case 0:
            playBoard.add(new JLabel("" + (ii + 1), SwingConstants.CENTER));
          default:
            playBoard.add(playBoardSquares[jj][ii]);
        }
      }
    }
  }
Exemplo n.º 2
0
 private JToolBar buildToolBar() {
   // build tool bar
   JToolBar toolBar = new JToolBar("Toolbar");
   toolBar.add(makeToolbarButton("stock_new.png", "New file", "New"));
   toolBar.add(makeToolbarButton("stock_open.png", "Open file", "Open"));
   toolBar.add(makeToolbarButton("stock_save.png", "Save file", "Save"));
   // run button is special
   runButton = makeToolbarButton("Play24.gif", "Run Program", "Run");
   toolBar.add(runButton);
   toolBar.add(makeToolbarButton("stock_text_left.png", "Pretty Print", "Pretty"));
   toolBar.addSeparator();
   toolBar.add(new JButton(copyAction));
   toolBar.add(new JButton(cutAction));
   toolBar.add(new JButton(pasteAction));
   return toolBar;
 }