'Swing Rock Paper Scissors Nuke Super Error

I'm trying to add a "nuke" function to this Rock Paper Scissors GUI application. However, my IDE complains about the super statement, it also complains that it cannot find symbol message. This was working perfectly before I added the nuke function. What could I add to get it to work?

import java.util.concurrent.TimeUnit;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class RpsNuke extends JFrame
   implements ActionListener
{
private final char moves[] = {'R', 'P', 'S', 'N'};
private JRadioButton rock, paper, scissors, nuke;
private JTextField display;

public void Rps()
{
super("Rock, Paper, Scissors, Nuke");

rock = new JRadioButton("   Rock   ", true);
paper = new JRadioButton("   Paper  ");
scissors = new JRadioButton(" Scissors ");
nuke = new JRadioButton(" Nuke ");
ButtonGroup rpsButtons = new ButtonGroup();
rpsButtons.add(rock);
rpsButtons.add(paper);
rpsButtons.add(scissors);
rpsButtons.add(nuke);

JButton go = new JButton("         Go         ");
go.addActionListener(this);

display = new JTextField(25);
display.setEditable(false);
display.setBackground(Color.yellow);

Container c = getContentPane();
c.setLayout(new FlowLayout());
c.add(rock);
c.add(paper);
c.add(scissors);
c.add(go);
c.add(nuke);
c.add(display);
if (nuke.isSelected()){
display.setText("Don't do it man");}
else {
display.setText("");}
}

/**
 *  returns -1 if the player wins,
 *  0 if it's a tie, and 1 if the computer wins
 */
private int nextPlay(char computerMove, char playerMove)
{
if ((computerMove == 'R'&&playerMove == 'S')||(computerMove == 'S'&&playerMove=='P')||(computerMove=='P'&&playerMove=='R')){
 return 1;}
else if ((computerMove == 'R'&&playerMove == 'R')||(computerMove=='S'&&playerMove=='S')||(computerMove=='P'&&playerMove=='P')){
 return 0;}
else if (playerMove == 'N'){
 return 2;}
return -1;  

}

public void actionPerformed(ActionEvent e)
{
 char playerMove, computerMove;
 playerMove = 0;
 if (rock.isSelected()){
   playerMove = 'R';}
 else if (paper.isSelected()){
   playerMove = 'P';}
else if (scissors.isSelected()){
  playerMove = 'S';}
else if (nuke.isSelected()){
  playerMove = 'N';}
int k = (int)(Math.random() * 3);
computerMove = moves[k];
int result = nextPlay(computerMove, playerMove);

if (result != 2)
{String msg = "  You said " + makeWord(playerMove) + ", I said " +
             makeWord(computerMove);
}
else if (result == 2)
{String msg = "It's too late, we're all dead!";
 TimeUnit.SECONDS.sleep(1);
 msg = "...";
 TimeUnit.SECONDS.sleep(1);
 msg = "Look at what you did, there's nothing left.";
 TimeUnit.SECONDS.sleep(1);
 msg = "Looks like we have to start over again...";
 main(null);                        
}             
else if (result < 0)
  msg += " -- you win.";
else if (result == 0)
  msg += " -- tie.";
else if (result > 0)
  msg += " -- I win.";
display.setText(msg);
}

private String makeWord(char move)
{
String word = "";

switch (move)
{
  case 'R': word = "rock"; break;
  case 'P': word = "paper"; break;
  case 'S': word = "scissors"; break;
  case 'N': word = "nuke"; break;
}
return word;
}

public static void main(String[] args)
{
  Rps window = new Rps();
  window.setBounds(300, 300, 300, 140);
  window.setDefaultCloseOperation(EXIT_ON_CLOSE);
  window.setVisible(true);
}
}



Solution 1:[1]

Remove the keyword void as that would mean that you are calling a method with the same name as your class. Rather, you are calling the constructor; not a method.

public void RpsNuke() { ... }

to

public RpsNuke() { ... }

Solution 2:[2]

Constructors dont use the void keyword. This is for methods only. Also match the constructor name with the declared type

public RpsNuke() {
    super("Rock, Paper, Scissors, Nuke");
    ...
}

The reason that you're seeing errors for the variable msg is that they are not visible in the scope of all the if statement blocks. To fix, you need to create one String rather when building one piece-meal by appending to it. Also don't use TimeUnit.SECONDS.sleep in Swing, this just prevents the EDT from updating the application. Use a Swing Timer Instead.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 blackpanther
Solution 2