0

I am about getting the hang of JavaFx programming and came across a weird construction in a Javafx controller file. The typical fx file, when generated usually contains a class :

@Override 
public void initialize(URL url, ResourceBundle rb)

Strangely, my last project, already a little advanced, has the following class instead:

@Override
public void start (Stage primaryStage) throws Exception {

I am using NetBeans on ubuntu and since I am still getting used to javafx and NetBeans (after a couple of years using python), I reckon I must have messed something up along the way without noticing.

My effort to simply replace the class "public void start" with "public void initialize" returns, without further explanations:

error: method does not override or implement a method from a supertype

In NetBeans, we can access a menu with the shortcut Alt+Ins, from where it is possible to adjust the Override settings, but I am afraid to use it without fully understanding the reasons of the mishap and the implications of messing with the settings. But I need the "initialize class" back, since I would like to execute some functions on program startup, what seems to be impossible from the "start" class.

What is the best way to restore the "initialize class" or it's properties?

Thanks in advance for any kind suggestion.

public class FXMLDocument_Controller extends Application {
@FXML
private Button dialog;
//other @FXMLs ..

/**
 *
 * @param actionEvent
 * @throws Exception
 */


}
//this is the class in the controller
@Override
public void start (Stage primaryStage) throws Exception {

 }

//this is the class I would like to have (back)
@Override
public void initialize(URL url, ResourceBundle rb) {
    System.out.println("hello world");
    // TODO
}



public void openMessageBox(ActionEvent actionEvent) {
         funtion
}

public void contextMenu (ContextMenuEvent contextMenuEvent) {
          function
}

public void openDialog(ActionEvent event) throws IOException{


}
1
  • Before you start with graphics, you should have a deep understanding of Java 101. Your question really is a fundamental misunderstanding about abstract classes. Commented Dec 25, 2016 at 6:38

1 Answer 1

1

It should be, public class FXMLDocument_Controller implements Initializable{ Then you can implement initialize

This method goes in the "main" class that extends Application and is the entry point to your program

@Override public void start (Stage primaryStage) throws Exception { }

In my netbeans -> new project I have a choices for 'javafx fxml application" and just "javafx application" among others. Maybe you chose the wrong one.

Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks, Brian ... works perfectly ..... yes, I have probably made the wrong choice at the beginning.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.