Let’s create a module named “Foo Bar”.
IWMenuBar.javaFind this line in the declarations part of class IWMenuBar:
:::java
final MenuItem sample_module = new MenuItem("Sample Module");
* Right above this line add the following line:
:::java
final MenuItem foo_bar = new MenuItem("Foo Bar");
* Then in function IWMenuBar(Stage stage) find the following line:
:::java
main_menu.getItems().addAll(sample_module, quit_item);
* Then add your item into the list of arguments of addAll() function, wherever you want the menu item to be, leaving quit_item at the end of the list. For example:
:::java
main_menu.getItems().addAll(sample_module, foo_bar, quit_item);
* Make your menu item handled by a universal handler. Find this string in IWMenuBar class:
:::java
sample_module.setOnAction(MEHandler);
And add your handler to this list:
:::java
foo_bar.setOnAction(MEHandler);
* Now find this code:
:::java
if(name.equals("Sample Module")) {
IWSampleModule sampleModule = new IWSampleModule(stage, urlTextField, searchTextField, webView);
}
And add you own code below:
:::java
if(name.equals("Foo Bar")) {
IWFooBar sampleModule = new IWFooBar(stage, urlTextField, searchTextField, webView);
}
* Finally, copy file IWSampleModule.java and paste it under the name of your class, e.g. IWFooBar.java (keep the IW prefix). Rename class IWSampleModule (e.g., IWFooBar).
*Test the result.
Congratulations! You’ve just created a new menu item and a separate class to handle it. This class has references to the stage, URL text field, search text field and the web view.