So my code tells me, at the if statement, that I need to insert != null check. Why does it tell me this and how do I create an if statement for a String variable? I am a beginner and appreciate the help but please leave an explanation with your answer as I don't always know exactly what I am doing without specific detail. Thanks a lot!
import java.util.Scanner;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Ellipse2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Game2 extends JPanel {
public void paint(Graphics g) { //creates a void in order to paint
Graphics2D g2d = (Graphics2D) g; //creates 2D graphics
g2d.setColor(Color.YELLOW); //sets color
g2d.fillOval(350, 15, 25, 70); //draws oval
g2d.fillOval(400, 15, 25, 70); //draws
g2d.setColor(Color.RED); //sets color
g2d.fillRect(350, 120, 77, 25); //draws rectangle
Scanner game = new Scanner (System.in); //creating a new scanner
String mood, Happy, Satisfied, Sad, Nervous; //creates string
System.out.println("How are you feeling today? Pick one of the following:");
System.out.println("");
System.out.println("Happy");
System.out.println("Satisfied");
System.out.println("Sad");
System.out.println("Nervous");
mood = game.nextLine();
if (mood = Satisfied) { //I NEED HELP WITH THIS. IT TELLS ME I NEED TO "Insert '!= null' check". WHY? THANKS IN ADVANCE!
g2d.setColor(Color.YELLOW); //sets color
g2d.fillOval(350, 15, 25, 70); //draws oval
g2d.fillOval(400, 15, 25, 70); //draws oval
g2d.setColor(Color.RED); //sets color
g2d.fillRect(350, 120, 77, 25); //draws rectangle
}
}
public static void main(String[] args) { //sets this class as main
JFrame frame = new JFrame("Ping Boom"); //sets title
frame.add(new Game2());
frame.setSize(800, 500); //sets size of window
frame.setVisible(true); //sets visibility as a boolean
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //sets the ability for the window to close on command
}
}