0

I have problem when trying to do create Sql statement using netbeans, javFX and MySQL. Here is my main method:

public void start(Stage primaryStage) throws Exception {
   primaryStage.setTitle("Create Product");
   Pane myPane = (Pane)FXMLLoader.load(getClass().getResource
("createProduct.fxml"));
   Scene myScene = new Scene(myPane);
   primaryStage.setScene(myScene);
   primaryStage.show();
}

public static void main(String[] args) {
    launch(args);
}

I design my user interface using javaFX and I store the whole panel as myPane as the code above. And here is my createProduct.fxml. It only contains a text field and a button.

<AnchorPane id="AnchorPane" prefHeight="200.0" prefWidth="320.0" xmlns:fx="http://javafx.com/fxml" fx:controller="it2297proj.SampleController">

And this is my event handler class. When button is on click, it will pass the whole panel into CreateProductController.

public class SampleController implements Initializable {
private SampleController myPane = null;

@FXML
private void handleButtonAction(ActionEvent event) {
    System.out.println("You clicked me!");
}
@FXML
private void createProduct(ActionEvent event){
CreateProductController controller = new CreateProductController();
boolean result = controller.create(myPane); //Error here
}

And inside my CreateProductController class, I just simply get the text and pass it into an entity.

public class CreateProductController {
public boolean create(SampleController panel){
    String name = panel.getnameTextField.getText();
}
}

However, there is an error at the event handler class, boolean result = controller.create(myPane); this line. The error message is The type of create(Sample Controller) class is erroneous. I have no idea why because it works fine in eclipse. Any help would be appreciated.

Thanks in advance.

1 Answers1

0

It's unclear which version of JavaFX you're using and what exactly you're trying to do. JavaFX 2.2 makes it really simple to create custom controllers. You can pass parameters into them directly from FXML, or programatically. If you're using version 2.2 you might benefit from reading Creating a Custom Control with FXML. The answer you're looking for might be there, especially in the section regarding FXMLLoaders.

This thread might be helpful too.

Community
  • 1
  • 1
axiopisty
  • 4,972
  • 8
  • 44
  • 73
  • Okay thanks a lot. I figure out already. I did not click the make resource after designing at the scene builder. Thanks –  Jun 19 '13 at 09:06