/** Place all the Swing widgets in the frame of this GUI. * Read the images from the directory "PieceImages". * Read the backgrounds from the directory "Backgrounds". * @post the GUI is visible. * @post a gray-scale version of each background image is created * and assigned the prefix "faded". */ public void layoutGUI() { ReadImages(); table = new JTable(myBoard) { public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component c = super.prepareRenderer( renderer, row, column); // We want renderer component to be // transparent so background image is visible if ( c instanceof JComponent) ((JComponent)c).setOpaque(false); return c; } // Override paint so as to show the table background public void paint( Graphics g ) { // paint an image in the table background if (background != null) { g.drawImage( background.getImage(), 0, 0, null, null ); } // Now let the paint do its usual work super.paint(g); } } ; // end table def // Describe how to display a Piece from the model table.setDefaultRenderer(Renderable.class, new PieceRenderer()); TableColumn column = null; if (myBoard != null) { // Set the dimensions for each column in the board to match the image */ for (int i = 0; i < myBoard.getColumnCount(); i++) { column = table.getColumnModel().getColumn(i); column.setMaxWidth(TileWidth); column.setMinWidth(TileWidth); } } // Define the layout manager that will control order of components getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); // Create a panel to hold the buttons JPanel buttonPane = new JPanel(); if (buttonList != null) { // For each button the plugin gave us, add it to the panel for (SmartButton aButton: buttonList) { aButton.addActionListener(aButton.getHandler()); if (aButton.getShortcut() != ' ') { aButton.setMnemonic(aButton.getShortcut()); } //System.out.println("adding button: " + aButton.getText()); buttonPane.add(aButton); } } buttonPane.setAlignmentX(Component.CENTER_ALIGNMENT); getContentPane().add(buttonPane); // Create a panel for the status information JPanel statusPane = new JPanel(); if (myStatus != null) { statusPane.add(myStatus); } statusPane.setAlignmentX(Component.CENTER_ALIGNMENT); getContentPane().add(statusPane); // Define the characteristics of the table that shows the game board table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setCellSelectionEnabled(false); table.setRowHeight(TileHeight); table.setOpaque(false); table.setShowGrid(false); table.setAlignmentX(Component.CENTER_ALIGNMENT); getContentPane().add(table); // Define the mouse listener that will handle player's clicks. table.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { int col = table.getSelectedColumn(); int row = table.getSelectedRow(); gameModel.makeMove(row, col); // Go make the move! } } ); // And handle window closing events addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); } // end layout