6 Replies - 330 Views - Last Post: 07 August 2017 - 10:59 AM Rate Topic: -----

#1 ejalur1980  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 02-August 17

Can't find getSource() in JavaFX

Posted 07 August 2017 - 07:21 AM

Hi all,

I have a JavaFX application I am building.

This is the Application file:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package projectthree;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 *
 * @author RL
 */
public class ProjectThree extends Application {
    
    @Override
    public void start(Stage stage) throws Exception {
        
        Parent root = 
                FXMLLoader.load(
                        getClass().
                        getResource("FXMLdocument.fxml"));
        Scene scene = new Scene(root, 700,250,Color.RED);    
        stage.setScene(scene);
        stage.show();
        
        
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
}





This is the fxml document:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.Insets?>
<?import javafx.geometry.Rectangle2D?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.TilePane?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="815.0" prefWidth="834.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="projectthree.FXMLDocumentController">
   <children>
      <TilePane hgap="10.0" layoutX="22.0" layoutY="68.0" prefHeight="161.0" prefWidth="788.0" vgap="10.0">
         <children>
            <ImageView fx:id="treeImageView" fitHeight="115.0" fitWidth="115.0" onMouseClicked="#handlePalette" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/tree.jpg" />
               </image>
            </ImageView>
            <ImageView fx:id="grassImageView" fitHeight="115.0" fitWidth="115.0" onMouseClicked="#handlePalette" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/Grass.jpg" />
               </image>
            </ImageView>
            <ImageView fx:id="brickImageView" fitHeight="115.0" fitWidth="115.0" onMouseClicked="#handlePalette" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/Brick.jpg" />
               </image>
            </ImageView>
            <ImageView fx:id="waterImageView" fitHeight="115.0" fitWidth="115.0" onMouseClicked="#handlePalette" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/water.jpg" />
               </image>
            </ImageView>
            <ImageView fx:id="sandImageView" fitHeight="115.0" fitWidth="115.0" onMouseClicked="#handlePalette" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/Sand.jpg" />
               </image>
            </ImageView>
            <ImageView fx:id="selected" fitHeight="115.0" fitWidth="115.0" pickOnBounds="true" preserveRatio="true" />
         </children>
         <padding>
            <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
         </padding>
      </TilePane>
      <Label contentDisplay="CENTER" layoutX="283.0" layoutY="25.0" text="Game Changer - Map Editor">
         <font>
            <Font name="System Bold" size="21.0" />
         </font></Label>
      <Button layoutX="29.0" layoutY="266.0" mnemonicParsing="false" text="Load Map" />
      <Button layoutX="29.0" layoutY="324.0" mnemonicParsing="false" onAction="#handleSave" text="Save Map" />
      <Label layoutX="29.0" layoutY="375.0" text="Map Name:" />
      <TextField fx:id="txtMapName" layoutX="26.0" layoutY="408.0" prefHeight="31.0" prefWidth="117.0" promptText="testmap1.map" />
      <GridPane gridLinesVisible="true" layoutX="250.0" layoutY="250.0" minHeight="100.0" minWidth="100.0" prefHeight="493.0" prefWidth="501.0">
        <columnConstraints>
          <ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" prefWidth="100.0" />
          <ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" prefWidth="100.0" />
        </columnConstraints>
        <rowConstraints>
          <RowConstraints maxHeight="100.0" minHeight="10.0" prefHeight="100.0" vgrow="SOMETIMES" />
          <RowConstraints maxHeight="100.0" minHeight="10.0" prefHeight="100.0" vgrow="SOMETIMES" />
          <RowConstraints maxHeight="100.0" minHeight="10.0" prefHeight="100.0" vgrow="SOMETIMES" />
            <RowConstraints maxHeight="100.0" minHeight="10.0" prefHeight="100.0" vgrow="SOMETIMES" />
            <RowConstraints maxHeight="100.0" minHeight="10.0" prefHeight="100.0" vgrow="SOMETIMES" />
        </rowConstraints>
         <children>
            <ImageView fx:id="treeImageView1" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="treeImageView2" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="treeImageView3" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="2">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="treeImageView4" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="3">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="treeImageView5" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="4">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="grassImageView3" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.rowIndex="1">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="grassImageView2" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="1">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="grassImageView1" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="2" GridPane.rowIndex="1">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="grassImageView4" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="3" GridPane.rowIndex="1">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="waterImageView1" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="4" GridPane.rowIndex="1">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="waterImageView2" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.rowIndex="2">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="waterImageView3" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="2">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="waterImageView4" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="2" GridPane.rowIndex="2">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="waterImageView5" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="3" GridPane.rowIndex="2">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="waterImageView6" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="4" GridPane.rowIndex="2">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="brickImageView1" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" opacity="0.79" pickOnBounds="true" preserveRatio="true" GridPane.rowIndex="3">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="brickImageView2" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" opacity="0.79" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="3">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="sandImageView1" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="2" GridPane.rowIndex="3">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="sandImageView2" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="3" GridPane.rowIndex="3">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="sandImageView3" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="4" GridPane.rowIndex="3">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="brickImageView3" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" opacity="0.79" pickOnBounds="true" preserveRatio="true" GridPane.rowIndex="4">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="sandImageView4" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="4">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="sandImageView5" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="2" GridPane.rowIndex="4">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="sandImageView6" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="3" GridPane.rowIndex="4">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
            <ImageView fx:id="brickImageView4" fitHeight="100.0" fitWidth="100.0" onMouseClicked="#handlePainting" opacity="0.79" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="4" GridPane.rowIndex="4">
               <viewport>
                  <Rectangle2D minX="5.0" minY="5.0" />
               </viewport>
            </ImageView>
         </children>
      </GridPane>
      <Label layoutX="29.0" layoutY="459.0" prefHeight="47.0" prefWidth="210.0" />
   </children>
</AnchorPane>






This is the controller class:

package projectthree;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;

/**
 *
 * @author RL
 */
public class FXMLDocumentController implements Initializable {
    
    @FXML
    private TextField txtMapName;
    
     
    private Image treeImage;
    private Image grassImage;
    private Image brickImage;
    private Image waterImage;
    private Image sandImage;
    private ArrayList<String> images;
    
    //private Image treeSelectedImage
    @FXML
    private ImageView treeImageView1;
    @FXML
    private ImageView treeImageView2;
    @FXML
    private ImageView treeImageView3;
    @FXML
    private ImageView treeImageView4;
    @FXML
    private ImageView treeImageView5;
    
    @FXML
    private ImageView grassImageView3;
    @FXML
    private ImageView grassImageView2;
    @FXML
    private ImageView grassImageView1;
    @FXML
    private ImageView grassImageView4;
    @FXML
    private ImageView waterImageView1;
    @FXML
    private ImageView waterImageView2;
    @FXML
    private ImageView waterImageView3;
    @FXML
    private ImageView waterImageView4;
    @FXML
    private ImageView waterImageView5;
    @FXML
    private ImageView waterImageView6;
    @FXML
    private ImageView brickImageView1;
    @FXML
    private ImageView brickImageView2;
    @FXML
    private ImageView brickImageView3;
    @FXML
    private ImageView brickImageView4;
    @FXML
    private ImageView sandImageView1;
    @FXML
    private ImageView sandImageView2;
    @FXML
    private ImageView sandImageView3;
    @FXML
    private ImageView sandImageView5;
    @FXML
    private ImageView sandImageView6;
    @FXML
    private ImageView sandImageView4;
    @FXML
    private ImageView selected;
    
    

    
    private ArrayList<ImageView> imageViewArrayL;
    @FXML
    private ImageView treeImageView;
    @FXML
    private ImageView grassImageView;
    @FXML
    private ImageView brickImageView;
    @FXML
    private ImageView waterImageView;
    @FXML
    private ImageView sandImageView;
    /**
     * Initializes the controller class.
     * @param url
     * @param rb
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO

        
       treeImage = new Image("projectthree/images/tree.jpg");
       grassImage = new Image("projectthree/images/Grass.jpg");
       brickImage = new Image("projectthree/images/Brick.jpg");
       waterImage = new Image("projectthree/images/water.jpg");
       sandImage =  new Image("projectthree/images/Sand.jpg");
       
       //treeImageView.setImage(treeImage);

       imageViewArrayL = new ArrayList<>();
       imageViewArrayL.add(treeImageView1);
       imageViewArrayL.add(treeImageView2);
       imageViewArrayL.add(treeImageView3);
       imageViewArrayL.add(treeImageView4);
       imageViewArrayL.add(treeImageView5);
       
       imageViewArrayL.add(grassImageView3);
       imageViewArrayL.add(grassImageView2);
       imageViewArrayL.add(grassImageView1);
       imageViewArrayL.add(grassImageView4);
       imageViewArrayL.add(waterImageView1);
       
       imageViewArrayL.add(waterImageView2);
       imageViewArrayL.add(waterImageView3);
       imageViewArrayL.add(waterImageView4);
       imageViewArrayL.add(waterImageView5);
       imageViewArrayL.add(waterImageView6);
       
       imageViewArrayL.add(brickImageView1);
       imageViewArrayL.add(brickImageView2);
       imageViewArrayL.add(sandImageView1);
       imageViewArrayL.add(sandImageView2);
       imageViewArrayL.add(sandImageView3);
       
       imageViewArrayL.add(brickImageView3);
       imageViewArrayL.add(sandImageView4);
       imageViewArrayL.add(sandImageView5);
       imageViewArrayL.add(sandImageView6);
       imageViewArrayL.add(brickImageView4);   
    }    

    
    @FXML
    private void handlePalette(MouseEvent event) {
        ImageView selectedView = (ImageView)event.getSource();
        selected.setImage(selectedView.getImage());
    }//endhandlePalette

    @FXML
    private void handlePainting(MouseEvent event) {
        images = new ArrayList<>();
        ImageView clickedImageView = (ImageView)event.getSource();
        clickedImageView.setImage(selected.getImage());
              
        
    }//end handlePainting

    @FXML
    private void handleSave(ActionEvent event) {
 //       images = new ArrayList<>();
          String imagesT = "";
//      String lblFileName = txtMapName.getText();
//         
//        //File fileName = new File("projectthree/outfiles/" + lblFileName);
//        //try
//        //{
//            //event.getSource();
//            //PrintWriter pw = new PrintWriter(fileName);
            //ImageView clickedImageView = (ImageView)event.getSource();
            //System.out.println("clickedImageView" + clickedImageView.getId());
            for(int i = 0; i < imageViewArrayL.size(); i++)
            {
                //ImageView selectedQA = (ImageView)imageViewArrayL.get(i);
                //System.out.println((ImageView)imageViewArrayL.get(i) + " QA " + selectedQA.getId());
    //           ImageView clickedImageView = (ImageView)event.getSource();
               ImageView selectedImage = (ImageView)imageViewArrayL.get(i);
               if(selectedImage.getImage() != null)
               {
                   if(selectedImage.getImage().getSource().equals(treeImageView.getImage().getSource()))
                    {
                        System.out.println(selectedImage.getImage().equals(treeImage));
                        System.out.println(treeImageView.getImage().equals(treeImage));
                         //images.add("T");
                       imagesT += "T";
                    }
                   else if (selectedImage.getImage().getSource().equals(grassImageView.getImage().getSource()))
                   {
                       System.out.println(selectedImage.getImage().equals(grassImage));
                       System.out.println(grassImageView.getImage().equals(grassImage));
                       //images.add("G");
                       imagesT += "G";
                   }
                   else if (selectedImage.getImage().getSource().equals(waterImageView.getImage().getSource()))
                   {
                       System.out.println(selectedImage.getImage().equals(waterImage));
                       System.out.println(waterImageView.getImage().equals(waterImage));
                       //images.add("B");
                       imagesT += "W";
                   }
                   else if (selectedImage.getImage().getSource().equals(brickImageView.getImage().getSource()))
                   {
                       System.out.println(selectedImage.getImage().equals(brickImage));
                       System.out.println(brickImageView.getImage().equals(brickImage));
                       //images.add("B");
                       imagesT += "B";
                   }
                   else if (selectedImage.getImage().getSource().equals(sandImageView.getImage().getSource()))
                   {
                       System.out.println(selectedImage.getImage().equals(sandImage));
                       System.out.println(sandImageView.getImage().equals(sandImage));
                       //images.add("B");
                       imagesT += "S";
                   }
                  
                   
                   
               }
             
            }//end for loop
            //System.out.println(images.size());
            //System.out.println("This is the image Array" + images.toString());
            System.out.println("debugging" + imagesT);
                  
            
    }
}





This error occurs on line 196 to 226
My main challenge is in the controller file where I am building a condition to be able to assign a String values to the reference variable.
These string values represent the images that are painted in the different image views within the gridpane.

Can someone guide to be able to use the right methods to do this comparisson between the clicked ImageViews and stored "fxid" ImageViews in the arrayList.

Thanks,
Ron

Is This A Good Question/Topic? 0
  • +

Replies To: Can't find getSource() in JavaFX

#2 NormR  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 640
  • View blog
  • Posts: 4,842
  • Joined: 25-December 13

Re: Can't find getSource() in JavaFX

Posted 07 August 2017 - 07:28 AM

Quote

This error occurs on line 196 to 226

Please copy the full text of the error message and paste it here. It has important info about the error.
Was This Post Helpful? 0
  • +
  • -

#3 ejalur1980  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 02-August 17

Re: Can't find getSource() in JavaFX

Posted 07 August 2017 - 07:40 AM

These are the errors I am getting:

ant -f C:\\Users\\XXXX\\Downloads\\ProjectThree\\ProjectThree jfxsa-run
init:
deps-clean:
Updating property file: C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\build\built-clean.properties
Deleting directory C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\build
clean:
init:
deps-jar:
Created dir: C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\build
Updating property file: C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\build\built-jar.properties
Created dir: C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\build\classes
Created dir: C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\build\empty
Created dir: C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\build\generated-sources\ap-source-output
Compiling 3 source files to C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\build\classes
C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\src\projectthree\FXMLDocumentController.java:197: error: cannot find symbol
if(selectedImage.getImage().getSource().equals(treeImageView.getImage().getSource()))
symbol: method getSource()
location: class Image
C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\src\projectthree\FXMLDocumentController.java:197: error: cannot find symbol
if(selectedImage.getImage().getSource().equals(treeImageView.getImage().getSource()))
symbol: method getSource()
location: class Image
C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\src\projectthree\FXMLDocumentController.java:204: error: cannot find symbol
else if (selectedImage.getImage().getSource().equals(grassImageView.getImage().getSource()))
symbol: method getSource()
location: class Image
C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\src\projectthree\FXMLDocumentController.java:204: error: cannot find symbol
else if (selectedImage.getImage().getSource().equals(grassImageView.getImage().getSource()))
symbol: method getSource()
location: class Image
C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\src\projectthree\FXMLDocumentController.java:211: error: cannot find symbol
else if (selectedImage.getImage().getSource().equals(waterImageView.getImage().getSource()))
symbol: method getSource()
location: class Image
C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\src\projectthree\FXMLDocumentController.java:211: error: cannot find symbol
else if (selectedImage.getImage().getSource().equals(waterImageView.getImage().getSource()))
symbol: method getSource()
location: class Image
C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\src\projectthree\FXMLDocumentController.java:218: error: cannot find symbol
else if (selectedImage.getImage().getSource().equals(brickImageView.getImage().getSource()))
symbol: method getSource()
location: class Image
C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\src\projectthree\FXMLDocumentController.java:218: error: cannot find symbol
else if (selectedImage.getImage().getSource().equals(brickImageView.getImage().getSource()))
symbol: method getSource()
location: class Image
C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\src\projectthree\FXMLDocumentController.java:225: error: cannot find symbol
else if (selectedImage.getImage().getSource().equals(sandImageView.getImage().getSource()))
symbol: method getSource()
location: class Image
C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\src\projectthree\FXMLDocumentController.java:225: error: cannot find symbol
else if (selectedImage.getImage().getSource().equals(sandImageView.getImage().getSource()))
symbol: method getSource()
location: class Image
10 errors
C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\nbproject\build-impl.xml:931: The following error occurred while executing this line:
C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\nbproject\build-impl.xml:271: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 1 second)
Was This Post Helpful? 0
  • +
  • -

#4 NormR  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 640
  • View blog
  • Posts: 4,842
  • Joined: 25-December 13

Re: Can't find getSource() in JavaFX

Posted 07 August 2017 - 08:06 AM

Quote

C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\src\projectthree\FXMLDocumentController.java:197: error: cannot find symbol
if(selectedImage.getImage().getSource().equals(treeImageView.getImage().getSource()))
symbol: method getSource()
location: class Image

The compiler can not find a definition for the getSource method in the Image class.

Where did you see the API doc for that method in that class?

JavaFX has this class:
javafx.scene.image.Image
Java SE has this class:
java.awt.Image

This post has been edited by NormR: 07 August 2017 - 08:09 AM

Was This Post Helpful? 0
  • +
  • -

#5 ejalur1980  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 02-August 17

Re: Can't find getSource() in JavaFX

Posted 07 August 2017 - 08:18 AM

View PostNormR, on 07 August 2017 - 08:06 AM, said:

Quote

C:\Users\XXXX\Downloads\ProjectThree\ProjectThree\src\projectthree\FXMLDocumentController.java:197: error: cannot find symbol
if(selectedImage.getImage().getSource().equals(treeImageView.getImage().getSource()))
symbol: method getSource()
location: class Image

The compiler can not find a definition for the getSource method in the Image class.

Where did you see the API doc for that method in that class?

JavaFX has this class:
javafx.scene.image.Image
Java SE has this class:
java.awt.Image


The getSource() method comes from event object?

Looks like I am using it where it is not supposed to be used.

Any idea how I can compare the Source Images of the ImageView?
Was This Post Helpful? 0
  • +
  • -

#6 NormR  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 640
  • View blog
  • Posts: 4,842
  • Joined: 25-December 13

Re: Can't find getSource() in JavaFX

Posted 07 August 2017 - 08:26 AM

Quote

The getSource() method comes from event object?

To find what classes have a method, click on the "Index" link at the top of the API doc page, select the first letter of the methods name and all the methods that start with that letter will be listed. Then do a Find for the name of the desired method.

Quote

how I can compare the Source Images

Read the API doc for the classes and see if any of the methods look useful.
Was This Post Helpful? 0
  • +
  • -

#7 ejalur1980  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 02-August 17

Re: Can't find getSource() in JavaFX

Posted 07 August 2017 - 10:59 AM

After going through the API docs, getSource() method is found in the event class.

So removing getSource() from my code solved the issues I was facing.


  private void handleSave(ActionEvent event) {
 //       images = new ArrayList<>();
          String imagesT = "";
      String lblFileName = txtMapName.getText();
      boolean fileFlag = ValidateFileName.isFileNameValid(lblFileName);
      if(fileFlag)
      {
          
      }
      else
        errorNotification.setText(lblFileName + " is not a valid file.");
      

//         
//        //File fileName = new File("projectthree/outfiles/" + lblFileName);
//        //try
//        //{
//            //event.getSource();
//            //PrintWriter pw = new PrintWriter(fileName);
            //ImageView clickedImageView = (ImageView)event.getSource();
            //System.out.println("clickedImageView" + clickedImageView.getId());
            for(int i = 0; i < imageViewArrayL.size(); i++)
            {
                //ImageView selectedQA = (ImageView)imageViewArrayL.get(i);
                //System.out.println((ImageView)imageViewArrayL.get(i) + " QA " + selectedQA.getId());
    //           ImageView clickedImageView = (ImageView)event.getSource();
               ImageView selectedImage = (ImageView)imageViewArrayL.get(i);
               if(selectedImage.getImage() != null)
               {
                   if(selectedImage.getImage().equals(treeImageView.getImage()))
                    {
                        System.out.println(selectedImage.getImage().equals(treeImage));
                        System.out.println(treeImageView.getImage().equals(treeImage));
                         //images.add("T");
                       imagesT += "T";
                    }
                   else if (selectedImage.getImage().equals(grassImageView.getImage()))
                   {
                       System.out.println(selectedImage.getImage().equals(grassImage));
                       System.out.println(grassImageView.getImage().equals(grassImage));
                       //images.add("G");
                       imagesT += "G";
                   }
                   else if (selectedImage.getImage().equals(waterImageView.getImage()))
                   {
                       System.out.println(selectedImage.getImage().equals(waterImage));
                       System.out.println(waterImageView.getImage().equals(waterImage));
                       //images.add("B");
                       imagesT += "W";
                   }
                   else if (selectedImage.getImage().equals(brickImageView.getImage()))
                   {
                       System.out.println(selectedImage.getImage().equals(brickImage));
                       System.out.println(brickImageView.getImage().equals(brickImage));
                       //images.add("B");
                       imagesT += "B";
                   }
                   else if (selectedImage.getImage().equals(sandImageView.getImage()))
                   {
                       System.out.println(selectedImage.getImage().equals(sandImage));
                       System.out.println(sandImageView.getImage().equals(sandImage));
                       //images.add("B");
                       imagesT += "S";
                   }
                  
                   
                   
               }
             
            }//end for loop
            System.out.println(images.size());
            System.out.println("This is the image Array" + images.toString());
            System.out.println("debugging" + imagesT);
            
            System.out.println("The String length: " + imagesT.length());
                  
            
    }
}



Thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1