不兼容的类型:场景无法转换为父JavaJDK netbeans

时间:2017-05-19 08:23:38

标签: java netbeans jdk1.6

我用java jdk创建了一个包含按钮的简单表单,当用户点击它显示第二个表单的按钮并关闭第一个表单时,我在netbeans中有这样的错误:

error: incompatible types: Scene cannot be converted to Parent
        Scene secondScene = new Scene(scene2, 300,250);
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output

现在是完整的开始代码:

public void start(Stage primaryStage) {
    GridPane grid1 = new GridPane();
	Button butt1 = new Button();
	butt1.setText("Applique KPPV");
    grid1.add(butt1, 2, 6);
    Scene scene1 = new Scene(grid1, 300, 250);
    primaryStage.setTitle("KNN With JDK");
    primaryStage.setScene(scene1);
    primaryStage.show();
		
	butt1.setOnAction(e->{
            GridPane grid = new GridPane();
        // Labels & inputs Settings
        Label number1 = new Label("Data 1 :");
        Label number2 = new Label("Data 2 :");
        Label number3 = new Label("Data 3 :");
        Label number4 = new Label("Data 4 :");
        Label number5 = new Label("Data 5 :");
        Label numberk = new Label("K :");
        Label resultat1 = new Label("The Result");
        TextField txt1 = new TextField();
        TextField txt2 = new TextField();
        TextField txt3 = new TextField();
        TextField txt4 = new TextField();
        TextField txt5 = new TextField();
        TextField txtk = new TextField();
        grid.add(number1, 0, 0);
        grid.add(number2, 0, 1);
        grid.add(number3, 0, 2);
        grid.add(number4, 0, 3);
        grid.add(number5, 0, 4);
        grid.add(numberk, 0, 5);
        grid.add(resultat1, 0, 7);
        grid.add(txt1, 1, 0);
        grid.add(txt2, 1, 1);
        grid.add(txt3, 1, 2);
        grid.add(txt4, 1, 3);
        grid.add(txt5, 1, 4);
        grid.add(txtk, 1, 5);
        Button butt = new Button();
        butt.setText("Applique KPPV");
        grid.add(butt, 0, 6);
        // My Main Method
        ///////////////////////////////////


        // ADDED THESE 5 LINES. NOW IT SHOWS A WINDOW WITH THESE VALUES FILLED IN
        txt1.setText("0.0");
        txt2.setText("0.0");
        txt3.setText("0.0");
        txt4.setText("0.0");
        txt5.setText("0.0");
        txtk.setText("10");
        double insertedInt = Double.parseDouble(txt1.getText());
        double insertedInt2 = Double.parseDouble(txt2.getText());
        double insertedInt3 = Double.parseDouble(txt3.getText());
        double insertedInt4 = Double.parseDouble(txt4.getText());
        double insertedInt5 = Double.parseDouble(txt5.getText());
                ///////////////////////////////////
        Scene scene = new Scene(grid, 300, 250);

        // Final Action
        butt.setOnAction(event -> {
        double[] query = { insertedInt, insertedInt2, insertedInt3, insertedInt4, insertedInt5 };

        int k = Integer.parseInt(txtk.getText());
        List<City> cityList = new ArrayList<City>();
        List<Result> resultList = new ArrayList<Result>();
        cityList.add(new City(instances[0], "IRIS0"));
        cityList.add(new City(instances[1], "IRIS1"));
        cityList.add(new City(instances[2], "IRIS2"));
        cityList.add(new City(instances[3], "IRIS3"));
        cityList.add(new City(instances[4], "IRIS4"));
        cityList.add(new City(instances[5], "IRIS5"));
        cityList.add(new City(instances[6], "IRIS6"));
        cityList.add(new City(instances[7], "IRIS7"));
        cityList.add(new City(instances[8], "IRIS8"));
        cityList.add(new City(instances[9], "IRIS9"));
        // find distances
        for (City city : cityList) {
            double dist = 0.0;
            for (int j = 0; j < city.cityAttributes.length; j++) {
                dist += Math.pow(city.cityAttributes[j] - query[j], 2);
            }
            double distance = Math.sqrt(dist);
            resultList.add(new Result(distance, city.cityName));

        }

        Collections.sort(resultList, new DistanceComparator());
        String[] ss = new String[k];
        for (int x = 0; x < k; x++) {
            ss[x] = resultList.get(x).cityName;
        }
        String majClass = findMajorityClass(ss);
        // System.out.println("The Nearest IRIS Class is : "+majClass);


            resultat1.setText(majClass);
        });
            Scene secondScene = new Scene(scene, 500,500);
            Stage secondStage = new Stage();
            secondStage.setScene(secondScene); // set the scene
            secondStage.setTitle("Second Form");
            secondStage.show();
            primaryStage.close(); // close the first stage (Window)
        });

    }

0 个答案:

没有答案