title: How can I test which image is currently in a specific ImageView and have a tailored output for each possible image?
body: <p>We've managed to get it so the images will be properly set from this list when the first button is clicked. However, now I need to have that information sent to handleUSPKeep method and I need to set the list ID for the image that was set into the ImageView into the line that is before the if statements in the handleUSPKeep method. I created a global int variable named i and I put where the ID is supposed to go. Is there a way that I could set what i is in each of the seven methods at the end of the program?</p>
  
  <p>CODE:</p>
  
  <pre><code>public class USPSCaseSpinController implements Initializable {
  
          private static List&lt;Image&gt; gunImages =  new ArrayList&lt;&gt;();
  
          public static int i;
  
          @FXML
          private static Label USPName;  
  
          @FXML
          private static Label USPWearName;
  
          @FXML
          private Button SpinUSPS;
  
          @FXML
          public static ImageView setUSPImage;
  
          @FXML
          private Button USPKeep;
  
          @FXML
          private Button USPDiscard;
  
  
          @FXML
          private void handleSpinMechBack(MouseEvent event) throws IOException{
          Parent handleInventoryBackParent = FXMLLoader.load(getClass().getResource("/csgocaseopener/OpenCase.fxml"));
          Scene OPBackScene = new Scene(handleInventoryBackParent);
          Stage handleInventoryBackStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
          handleInventoryBackStage.setScene(OPBackScene);
          handleInventoryBackStage.show();
          }
  
  
          @FXML
          private void SpinUSPSCase(ActionEvent event) throws IOException{
          gunImages.add(new Image("GunImages/USPLead Conduit.png"));
          gunImages.add(new Image("GunImages/USPNight Ops.png"));
          gunImages.add(new Image("GunImages/USPTorque.png"));
          gunImages.add(new Image("GunImages/USPGaurdian.png"));
          gunImages.add(new Image("GunImages/USPCyrex.png"));
          gunImages.add(new Image("GunImages/USPCaiman.png"));
          gunImages.add(new Image("GunImages/USPKill Confirmed.png"));
              Random rand = new Random();
              int gunSelect = rand.nextInt(99)+1;
              if(gunSelect&lt;=30){
              LeadConduitUSPS();
              USPName.setText("Lead Conduit");
              }
              else if(gunSelect&gt;=31 &amp;&amp; gunSelect&lt;=60){
              NightOpsUSPS();
              USPName.setText("Night Ops");
              }
              else if(gunSelect&gt;=61 &amp;&amp; gunSelect&lt;=90){
              TorqueUSPS(); 
              USPName.setText("Torque");
              }
              else if(gunSelect&gt;=91 &amp;&amp; gunSelect&lt;=93.5){
              GuardianUSPS();
              USPName.setText("Guardian");
              }
              else if(gunSelect&gt;=94.5 &amp;&amp; gunSelect&lt;=97){
              CyrexUSPS();
              USPName.setText("Cyrex");
              }
              else if(gunSelect&gt;=98 &amp;&amp; gunSelect&lt;=99){
              CaimanUSPS();
              USPName.setText("Caiman");
              }
              else if(gunSelect==100){
              KillConfirmedUSPS();
              USPName.setText("Kill Confirmed");
              }
              SpinUSPS.setDisable(true);
              USPKeep.setVisible(true);
              USPDiscard.setVisible(true);
          }
  
          @FXML
          private void handleUSPDiscard(ActionEvent event) throws IOException{
          SpinUSPS.setDisable(false);
          USPKeep.setVisible(false);
          USPDiscard.setVisible(false);
          USPName.setText("");
          USPWearName.setText("");
          setUSPImage.setImage(null);
      }
  
          @FXML
          public void handleUSPKeep(ActionEvent event) throws IOException{
          SpinUSPS.setDisable(false);
          USPKeep.setVisible(false);
          USPDiscard.setVisible(false);
          USPName.setText("");
          USPWearName.setText("");
          setUSPImage.setImage(null);
  
  
          ImageView setUSPImage = new ImageView(gunImages.get(i));
  
          if(setUSPImage.getImage().equals(gunImages.get(0))){
              System.out.println("Lead Conduit");
          }
          else if(setUSPImage.getImage().equals(gunImages.get(1))){
              System.out.println("Night Ops");
          }
          else if(setUSPImage.getImage().equals(gunImages.get(2))){
              System.out.println("Torque");
          }
          else if(setUSPImage.getImage().equals(gunImages.get(3))){
              System.out.println("Guardian");
          }
          else if(setUSPImage.getImage().equals(gunImages.get(4))){
              System.out.println("Cyrex");
          }
          else if(setUSPImage.getImage().equals(gunImages.get(5))){
              System.out.println("Caiman");
          }
          else if(setUSPImage.getImage().equals(gunImages.get(6))){
              System.out.println("Kill Confirmed");
          }
  
      }
  
          public static void LeadConduitUSPS(){
          setUSPImage.setImage(gunImages.get(0));
          i =0;
          Random rand = new Random();
          int wareSelect = rand.nextInt(99)+1;
  
          if(wareSelect&lt;=10){ //Calculates the ware the gun has
              USPWearName.setText("Factory New");
          }
          else if(wareSelect&gt;=11 &amp;&amp; wareSelect&lt;=25){
              USPWearName.setText("Minimal Wear");
          }
          else if(wareSelect&gt;=26 &amp;&amp; wareSelect&lt;=60){
              USPWearName.setText("Field Tested");
          }
          else if(wareSelect&gt;=61 &amp;&amp; wareSelect&lt;=80){
              USPWearName.setText("Well Worn");
          }
          else if(wareSelect&gt;=81){
              USPWearName.setText("Battle Scarred");
          }
      }
      public static void NightOpsUSPS(){
          setUSPImage.setImage(gunImages.get(1));
          i=1;
          Random rand = new Random();
          double wareSelect = rand.nextInt(99)+1;
  
          if(wareSelect&lt;=10){ //Calculates the ware the gun has
              USPWearName.setText("Factory New");
          }
          else if(wareSelect&gt;=11 &amp;&amp; wareSelect&lt;=25){
              USPWearName.setText("Minimal Wear");
          }
          else if(wareSelect&gt;=26 &amp;&amp; wareSelect&lt;=60){
              USPWearName.setText("Field Tested");
          }
          else if(wareSelect&gt;=61 &amp;&amp; wareSelect&lt;=80){
              USPWearName.setText("Well Worn");
          }
          else if(wareSelect&gt;=81){
              USPWearName.setText("Battle Scarred");
          }
      }
      public static void TorqueUSPS(){
          setUSPImage.setImage(gunImages.get(2));
          i=2;
          Random rand = new Random();
          double wareSelect = rand.nextInt(99)+1;
  
          if(wareSelect&lt;=10){ //Calculates the ware the gun has
              USPWearName.setText("Factory New");
          }
          else if(wareSelect&gt;=11 &amp;&amp; wareSelect&lt;=25){
              USPWearName.setText("Minimal Wear");
          }
          else if(wareSelect&gt;=26 &amp;&amp; wareSelect&lt;=60){
              USPWearName.setText("Field Tested");
          }
          else if(wareSelect&gt;=61 &amp;&amp; wareSelect&lt;=80){
              USPWearName.setText("Well Worn");
          }
          else if(wareSelect&gt;=81){
              USPWearName.setText("Battle Scarred");
          }
      }
      public static void GuardianUSPS(){
          setUSPImage.setImage(gunImages.get(3));    
          i=3;
          Random rand = new Random();
          double wareSelect = rand.nextInt(99)+1;
  
          if(wareSelect&lt;=10){ //Calculates the ware the gun has
              USPWearName.setText("Factory New");
          }
          else if(wareSelect&gt;=11 &amp;&amp; wareSelect&lt;=50){
              USPWearName.setText("Minimal Wear");
          }
          else if(wareSelect&gt;=51){
              USPWearName.setText("Field Tested");
          }
      }
      public static void CyrexUSPS(){
          setUSPImage.setImage(gunImages.get(4));  
          i=4;
          Random rand = new Random();
          double wareSelect = rand.nextInt(99)+1;
  
          if(wareSelect&lt;=10){ //Calculates the ware the gun has
              USPWearName.setText("Factory New");
          }
          else if(wareSelect&gt;=11 &amp;&amp; wareSelect&lt;=25){
              USPWearName.setText("Minimal Wear");
          }
          else if(wareSelect&gt;=26 &amp;&amp; wareSelect&lt;=60){
              USPWearName.setText("Field Tested");
          }
          else if(wareSelect&gt;=61 &amp;&amp; wareSelect&lt;=80){
              USPWearName.setText("Well Worn");
          }
          else if(wareSelect&gt;=81){
              USPWearName.setText("Battle Scarred");
          }
      }
      public static void CaimanUSPS(){
          setUSPImage.setImage(gunImages.get(5));
          i=5;
          Random rand = new Random();
          double wareSelect = rand.nextInt(99)+1;
  
          if(wareSelect&lt;=10){ //Calculates the ware the gun has
              USPWearName.setText("Factory New");
          }
          else if(wareSelect&gt;=11 &amp;&amp; wareSelect&lt;=35){
              USPWearName.setText("Minimal Wear");
          }
          else if(wareSelect&gt;=36 &amp;&amp; wareSelect&lt;=75){
              USPWearName.setText("Field Tested");
          }
          else if(wareSelect&gt;=76){
              USPWearName.setText("Well Worn");
          }
      }
      public static void KillConfirmedUSPS(){
          setUSPImage.setImage(gunImages.get(6));
          i=6;
          Random rand = new Random();
          double wareSelect = rand.nextInt(99)+1;
  
          if(wareSelect&lt;=10){ //Calculates the ware the gun has
              USPWearName.setText("Factory New");
          }
          else if(wareSelect&gt;=11 &amp;&amp; wareSelect&lt;=24){
              USPWearName.setText("Minimal Wear");
          }
          else if(wareSelect&gt;=36 &amp;&amp; wareSelect&lt;=60){
              USPWearName.setText("Field Tested");
          }
          else if(wareSelect&gt;=61 &amp;&amp; wareSelect&lt;=85){
              USPWearName.setText("Well Worn");
          }
          else if(wareSelect&gt;=86){
              USPWearName.setText("Battle Scarred");
          }
      }
  
      @Override
      public void initialize(URL url, ResourceBundle rb) {
          // TODO
      }   
  }
  </code></pre>