public void actionPerformed(ActionEvent e) { if (e.getSource() == easy) { invSpeed = 50000; bombN = 1; timeDifficulty1 = 1000; distanceLimit = 400; monsterMultiplier = 1; multiplier = 1; setup(); } else if (e.getSource() == hard) { invSpeed = 30000; bombN = 4; timeDifficulty1 = 500; distanceLimit = 200; monsterMultiplier = 2; multiplier = 2; setup(); } else if (e.getSource() == back) { r = null; menu.setVisible(true); back.setVisible(false); this.revalidate(); repaint(); } else if (e.getSource() == howTo) { menu.removeAll(); menu.add(howToBack); menu.add(howToIMGL); menu.revalidate(); menu.repaint(); } else if (e.getSource() == howToBack) { menu.remove(howToIMGL); menu.remove(howToBack); menu.add(keyboardSpeedL1); menu.add(keyboardSpeedL2); menu.add(easy); menu.add(hard); menu.add(howTo); menu.add(onePlayerRB); menu.add(twoPlayerRB); menu.add(mouseRB); menu.add(keyboardRB); menu.add(keyboardSpeedS1); menu.add(keyboardSpeedS2); menu.add(musicCB); menu.add(highscoreL); menu.add(menuIMGL); menu.revalidate(); menu.repaint(); } }
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); }