@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; }
static void buildGUI() { // Need this size to balance axes. frame.setSize(520, 690); frame.setTitle("DrawTool"); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); Container cPane = frame.getContentPane(); // Status label on top. Unused for now. statusLabel.setOpaque(true); statusLabel.setBackground(Color.white); cPane.add(statusLabel, BorderLayout.NORTH); // Build the input/output elements at the bottom. JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createLineBorder(Color.black)); panel.setBackground(inputPanelColor); panel.setLayout(new GridLayout(2, 1)); panel.add(outputLabel); JPanel bottomPanel = new JPanel(); bottomPanel.setBackground(inputPanelColor); bottomPanel.add(inputField); bottomPanel.add(new JLabel(" ")); JButton enterButton = new JButton("Enter"); enterButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent a) { hasEntered = true; } }); bottomPanel.add(enterButton); panel.add(bottomPanel); if (!sequencingOn) { cPane.add(panel, BorderLayout.SOUTH); } // Drawing in the center. drawArea = new DrawTool(); if (sequencingOn) { frame.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent e) { handleKeyTyped(e); } }); } cPane.add(drawArea, BorderLayout.CENTER); drawArea.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { handleMouseClick(e); } public void mouseReleased(MouseEvent e) { handleMouseReleased(e); } }); drawArea.addMouseMotionListener( new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { handleMouseDragged(e); } }); }
private void makeMenuScreen() { menu = new JPanel(); menu.setBackground(Color.BLACK); menu.setLayout(null); menu.setBounds(0, 0, width, height); try { BufferedImage menuIMG = ImageIO.read(this.getClass().getResource("/Resources/MenuBackground.png")); // BufferedImage menuIMG = ImageIO.read(new // File("M:/ComputerProgrammingJava/InsaneMouse_03/src/Resources/MenuBackground.png")); menuIMGL = new JLabel( new ImageIcon( menuIMG.getScaledInstance( (int) (width * 0.8), (int) (height * 0.8), Image.SCALE_SMOOTH))); menuIMGL.setBounds(0, 0, width, height); } catch (Exception e) { } highscoreL = new JLabel(String.valueOf(highscore)); highscoreL.setBackground(Color.darkGray); highscoreL.setBounds((width / 2) + 100, (height / 2) + 70, 500, 100); highscoreL.setForeground(Color.white); easy = new JButton("Easy"); hard = new JButton("Hard"); easy.addActionListener(this); hard.addActionListener(this); easy.setBounds((width / 2) - 60, (height / 2) - 50, 120, 20); hard.setBounds((width / 2) - 60, height / 2 - 10, 120, 20); onePlayerRB = new JRadioButton("One Player"); twoPlayerRB = new JRadioButton("Two Player"); mouseRB = new JRadioButton("Mouse (Player 1)"); keyboardRB = new JRadioButton("Keyboard (Player 1)"); keyboardSpeedS1 = new JSlider(JSlider.HORIZONTAL, 10, 300, 50); keyboardSpeedS2 = new JSlider(JSlider.HORIZONTAL, 10, 300, 50); musicCB = new JCheckBox("Music"); onePlayerRB.setBackground(null); twoPlayerRB.setBackground(null); mouseRB.setBackground(null); keyboardRB.setBackground(null); keyboardSpeedS1.setBackground(null); keyboardSpeedS2.setBackground(null); musicCB.setBackground(null); onePlayerRB.setForeground(Color.WHITE); twoPlayerRB.setForeground(Color.WHITE); mouseRB.setForeground(Color.WHITE); keyboardRB.setForeground(Color.WHITE); keyboardSpeedS1.setForeground(Color.WHITE); keyboardSpeedS2.setForeground(Color.WHITE); musicCB.setForeground(Color.WHITE); ButtonGroup playerChoice = new ButtonGroup(); playerChoice.add(onePlayerRB); playerChoice.add(twoPlayerRB); onePlayerRB.setSelected(true); ButtonGroup peripheralChoice = new ButtonGroup(); peripheralChoice.add(mouseRB); peripheralChoice.add(keyboardRB); mouseRB.setSelected(true); musicCB.setSelected(true); onePlayerRB.setBounds((width / 2) + 100, (height / 2) - 50, 100, 20); twoPlayerRB.setBounds((width / 2) + 100, (height / 2) - 30, 100, 20); mouseRB.setBounds((width / 2) + 100, (height / 2), 200, 20); keyboardRB.setBounds((width / 2) + 100, (height / 2) + 20, 200, 20); keyboardSpeedS1.setBounds(width / 2 - 120, height / 2 + 100, 200, 50); keyboardSpeedS2.setBounds(width / 2 - 120, height / 2 + 183, 200, 50); musicCB.setBounds((width / 2) + 100, (height / 2) + 50, 100, 20); keyboardSpeedL1 = new JLabel("Keyboard Speed (Player One)"); keyboardSpeedL1.setForeground(Color.WHITE); keyboardSpeedL1.setBounds(width / 2 - 113, height / 2 + 67, 200, 50); keyboardSpeedL2 = new JLabel("Keyboard Speed (Player Two)"); keyboardSpeedL2.setForeground(Color.WHITE); keyboardSpeedL2.setBounds(width / 2 - 113, height / 2 + 150, 200, 50); howTo = new JButton("How To Play"); howTo.addActionListener(this); howTo.setBounds((width / 2) - 60, height / 2 + 30, 120, 20); try { BufferedImage howToIMG = ImageIO.read(this.getClass().getResource("/Resources/HowTo.png")); // BufferedImage howToIMG = ImageIO.read(new // File("M:/ComputerProgrammingJava/InsaneMouse_03/src/Resources/HowTo.png")); howToIMGL = new JLabel(new ImageIcon(howToIMG)); howToIMGL.setBounds( width / 2 - howToIMG.getWidth() / 2, height / 2 - howToIMG.getHeight() / 2, howToIMG.getWidth(), howToIMG.getHeight()); } catch (Exception e) { } howToBack = new JButton("X"); howToBack.setBounds( (int) (width / 2 + width * 0.25) - 50, (int) (height / 2 - height * 0.25), 50, 50); howToBack.setBackground(Color.BLACK); howToBack.setForeground(Color.WHITE); howToBack.addActionListener(this); menu.add(easy); menu.add(hard); menu.add(howTo); menu.add(highscoreL); menu.add(onePlayerRB); menu.add(twoPlayerRB); menu.add(mouseRB); menu.add(keyboardRB); menu.add(keyboardSpeedL1); menu.add(keyboardSpeedL2); menu.add(keyboardSpeedS1); menu.add(keyboardSpeedS2); menu.add(musicCB); menu.add(menuIMGL); back = new JButton("Back"); back.setBounds(width / 2 - 40, height / 2, 100, 20); back.addActionListener(this); back.setVisible(false); this.add(back); }