How to call Java method in JavaFX menu -


i'm new javafx. created simple menu.

menubar menubar = new menubar();          // file menu - new, save, exit         menu menu = new menu("file");         menu.getitems().add(new menuitem("new"));         menu.getitems().add(new menuitem("save"));         menu.getitems().add(new separatormenuitem());         menu.getitems().add(new menuitem("exit"));          menubar.getmenus().add(menu);          // options menu - preferences         menu options = new menu("options");         options.getitems().add(new menuitem("preferences"));          menubar.getmenus().add(options);          // menu -         menu = new menu("help");         help.getitems().add(new menuitem("about"));          menubar.getmenus().add(help);          menubar.prefwidthproperty().bind(primarystage.widthproperty());          root.getchildren().add(menubar);         primarystage.setscene(scene);         primarystage.show();     } 

can tell me how can call java method when click on menu? start wan call java method when click exit.

 public void programexit(){         system.exit(0);      } 

instead of menu.getitems().add(new menuitem("exit")); write:

menuitem menuitem = new menuitem("exit"); menuitem.setonaction(new eventhandler<actionevent>() {     @override public void handle(actionevent e) {         system.exit(0);     } }); menu.getitems().add(menuitem); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -