Preface: In my other article, "My approach to naming Java identifiers," I mentioned that I wrote the method of returning the control in a way similar to: W_borderpane ().
Now I propose a hierarchical classification method for writing UI interfaces through code:
Example code:
//Root Container Private StaticBorderpane w_borderpanebasis () {//CreateBorderpane _borderpanebasis =NewBorderpane (); //#自我定义_borderpanebasis.setbackground (NewBackground (NewBackgroundfill (paint.valueof ("#333333"),NULL,NULL))); //#添加子级组件_borderpanebasis.settop (W_menubarbasis ()); //return return_borderpanebasis; } //Main Menu Bar Private StaticMenuBar w_menubarbasis () {MenuBar _menubar=NewMenuBar (); _menubar.getmenus (). Add (W_menuproject ()); return_menubar; } //Menu "Items" Private StaticMenu W_menuproject () {menu _menuproject=NewMenu ("Project"); return_menuproject; }
@Override publicvoidthrows exception{ Primarystage.settitle ("translation assistant"); New Scene (W_borderpanebasis (),. Primarystage.setresizable (false); Primarystage.setscene (_scene); Primarystage.geticons (). Add (new Image (Windowmain. Class. getResourceAsStream ("Resource/img/dao.png")); Primarystage.show (); }
About javafx--my hierarchical classification method for writing UI interfaces through code