title: I need help making buttons appear and disappear on JPanel (if statement not working to check if a condition for an int is met)
body: <p>Nothing appears to be wrong with this from what I have seen</p>
  <p>Code for Driver:</p>
  <pre><code>import javax.swing.JFrame;
  import java.util.Scanner;
  import java.util.Random;
  
  public class rpsDriver{
  
  public static void main(String[] args){
  
  
  //jpanel stuff
  
    JFrame frame = new JFrame(&quot;Rock Paper Scissors Game&quot;);
    frame.setSize(1280,720);
    frame.setLocation(250, 50);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new rpsPanel());
    frame.setVisible(true);
  
  
  
  }//end main
  
  }//end class
  </code></pre>
  <hr />
  <p>The problem I have is that when I run the code and me or the computer gets to 3 wins the end screen that says you win/lose appears but the rock, paper, scissors button on the left is still there (and I would like for it to disappear). Also, I would like to add buttons below the thing that says you win/lose that will let you restart the game (making userScore, tieScore, and compScore = 0), and a button that ends the game (closes the panel and ends the run). I'd appreciate any help.</p>
  <p>Code for the JPanel (the one I have problem with):</p>
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import java.io.*;
  import java.awt.image.BufferedImage;
  import javax.imageio.ImageIO; 
  import javax.swing.ImageIcon.*;
  import java.util.Random;
  import java.util.concurrent.TimeUnit;
  
  public class rpsPanel extends JPanel{
  
  Random rand = new Random();
  
  //variables used in code
  String compChoice = &quot;&quot;;
  int userNum; //number that corresponds to a choice
  int compNum; //number that corresponds to a choice
  int num;
  int score; //score to decide who wins
  String result = &quot;&quot;;
  String userChoice = &quot;&quot;;
  //win and tie count
  int userScore = 0;
  int compScore = 0;
  int tieScore = 0;
  
  
  //boolean variables for each choice
  static JFrame frame;
  boolean rock = false;
  boolean paper = false;
  boolean scissors = false;
  
  
  
  public void paintComponent(Graphics g){
  
  setLayout(null);
  //background
  //     setLayout(new BoxLayout());
  ImageIcon wooden = new ImageIcon(&quot;woodenBG.jpg&quot;);
  g.drawImage(wooden.getImage(), 0, 0, 1280, 720, null);
  g.setFont(new Font(&quot;Serif&quot;, Font.BOLD, 30));
  g.setColor(Color.BLACK);
  g.drawString(&quot;VS&quot; , 630, 385);
    
  //images for rock,paper, scissors
  ImageIcon rockChoice = new ImageIcon(&quot;rock.png&quot;);
  ImageIcon paperChoice = new ImageIcon(&quot;paper.jpg&quot;);
  ImageIcon scissorsChoice = new ImageIcon(&quot;scissors.jpg&quot;);
    
  /*displays the choice the user made*/
  if (rock){   
  g.drawImage(rockChoice.getImage(), 350, 300, 200, 200, null);
  }
  else if (paper){      
  g.drawImage(paperChoice.getImage(), 350, 300, 200, 200, null);
  }
  else if (scissors){      
  g.drawImage(scissorsChoice.getImage(), 350, 300, 200, 200, null);
  }
  /**********************************/
    
         
    
  /* computer makes choice after user */
  if(rock || paper || scissors){
  num = rand.nextInt(9);
       
       if(num == 1 || num == 4 || num == 7){ //rock choice
          compChoice = &quot;rock&quot;;
          compNum = 1;
          g.drawImage(rockChoice.getImage(), 800, 300, 200, 200, null);
       }
       else if (num == 2 || num == 5 || num == 8){//paper choice
          compChoice = &quot;paper&quot;;
          compNum = 2;
          g.drawImage(paperChoice.getImage(), 800, 300, 200, 200, null);
       }
       else if(num == 3 || num == 6 || num == 0){//scissors choice
          compChoice = &quot;scissors&quot;;
          compNum = 3;
          g.drawImage(scissorsChoice.getImage(), 800, 300, 200, 200, null);
       }
    }
    /**********************************/
    
    /*the logic part to decide the winner*/
    score = userNum - compNum;
    if(score == -2 || score == 1){
       result = &quot;win&quot;;
       userScore++;
    }
          
    if(score == 2 || score == -1){
       result = &quot;loss&quot;;
       compScore++;
    }
          
    if ((score == 0) &amp;&amp; (rock || paper || scissors)){
       result = &quot;tie&quot;;
       tieScore++;
    }
    /***************************************/
    
    
    //Displays the outcome
    g.setFont(new Font(&quot;Serif&quot;, Font.BOLD, 40));
    g.setColor(Color.BLACK);
    g.drawString(&quot;The outcome: &quot; + result, 425, 100); 
    
    
    //This shows the score of you and the computer
    g.setFont(new Font(&quot;Serif&quot;, Font.BOLD, 30));
    g.setColor(Color.BLACK);
    g.drawString(&quot;Your score is &quot; + userScore, 25, 50);
  
    g.setFont(new Font(&quot;Serif&quot;, Font.BOLD, 30));
    g.setColor(Color.BLACK);
    g.drawString(&quot;The computer's score is &quot; + compScore, 925, 50);
    
    g.setFont(new Font(&quot;Serif&quot;, Font.BOLD, 30));
    g.setColor(Color.BLACK);
    g.drawString(&quot;The amount of ties that occured are &quot; + tieScore, 400, 50);
    
    //user wins the game after user wins 3 rounds
    if(userScore &gt;= 3){
       g.setColor(new Color(0, 0, 0, 150));
       g.fillRect(0,0,1280,720);
       g.setFont(new Font(&quot;Serif&quot;, Font.BOLD, 75));
       g.setColor(new Color(57, 255, 20));
       g.drawString(&quot;You WIN!&quot;, 300, 330);
       
    
    }
    
    //computer wins the game after computer wins 3 rounds
    if(compScore &gt;= 3){
       g.setColor(new Color(0, 0, 0, 150));
       g.fillRect(0,0,1280,720);
       g.setFont(new Font(&quot;Serif&quot;, Font.BOLD, 75));
       g.setColor(Color.RED);
       g.drawString(&quot;You LOSE! Try again&quot;, 400, 330);
    
    }
  
     }//ends the paintcomponent class
  
     public rpsPanel(){      
     setLayout(null);
    
    
    //images for rock, paper, scissors
    Icon rPic = new ImageIcon(new ImageIcon(&quot;rock.png&quot;).getImage().getScaledInstance(70, 70, Image.SCALE_DEFAULT));
    Icon pPic = new ImageIcon(new ImageIcon(&quot;paper.jpg&quot;).getImage().getScaledInstance(70, 70, Image.SCALE_DEFAULT));
    Icon sPic = new ImageIcon(new ImageIcon(&quot;scissors.jpg&quot;).getImage().getScaledInstance(70, 70, Image.SCALE_DEFAULT));
    
    
    /* buttons for rock paper scissors */
    JButton rockBTN = new JButton(rPic); //rock button
    rockBTN.addActionListener(new rockListener());
    rockBTN.setBounds(20, 200, 70, 70);
    add(rockBTN);
  
    JButton paperBTN = new JButton(pPic); //paper button
    paperBTN.addActionListener(new paperListener());
    paperBTN.setBounds(20, 300, 70, 70);
    add(paperBTN);
    
    JButton scissorsBTN = new JButton(sPic); //scissors button
    scissorsBTN.addActionListener(new scissorsListener());
    scissorsBTN.setBounds(20, 400, 70, 70);
    add(scissorsBTN);
         
    /*************************************/
    
    
    
    
    /* Creates the buttons to restart or end the game when one team has 3 wins */
    
    JButton restartBTN = new JButton(&quot;RESTART&quot;);
    restartBTN.addActionListener(new restartListener());
    
    JButton endGameBTN = new JButton(&quot;END&quot;);
    endGameBTN.addActionListener(new endGameListener());
    endGameBTN.setBounds(300,500,50,50);
    
    /*****************************************************/
   
   if(userScore &lt; 3 || compScore &lt; 3){
       rockBTN.setVisible(true);
       paperBTN.setVisible(true);
       scissorsBTN.setVisible(true);
       restartBTN.setVisible(false);
       endGameBTN.setVisible(false);
    }
    else if (userScore &gt;= 3 || compScore &gt;= 3){
       rockBTN.setVisible(false);
       paperBTN.setVisible(false);
       scissorsBTN.setVisible(false);
       restartBTN.setVisible(true);
       endGameBTN.setVisible(true);
       
    }
    
    }
  
     /* listeners for each button */ 
    private class rockListener implements ActionListener{  //rock  
    public void actionPerformed(ActionEvent e){
       //repaints game with the rock choice
       rock = true;
       repaint();
       revalidate();
       paper = false;
       scissors = false;
       userNum = 1;
       
      
       
    }  
     }
  
    private class paperListener implements ActionListener{ //paper
    public void actionPerformed(ActionEvent e){        
       //repaints game with the paper choice
       paper = true;
       repaint();
       revalidate();
       rock = false;
       scissors = false;
       userNum = 2;
    }
     }
  
     private class scissorsListener implements ActionListener{//scissors
    public void actionPerformed(ActionEvent e){
       //repaints game with the scissors choice
       scissors = true;
       repaint();
       revalidate();
       paper = false;
       rock = false;
       userNum = 3;
    }
     }
  
     private class restartListener implements ActionListener{//restartBTN
    public void actionPerformed(ActionEvent e){
    //if button is clicked it will restart game with score at 0
    
    }
     }
  
     private class endGameListener implements ActionListener{//restartBTN
    public void actionPerformed(ActionEvent e){
    //if button is clicked it will end the game, remove panel, and end the run
    
    }
     }
  
  
    
    /**********************************************/  
   }//ends rpsPanel
  </code></pre>