javafx.fxml.Initializable Java Examples
The following examples show how to use
javafx.fxml.Initializable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GameView.java From CrazyAlpha with GNU General Public License v2.0 | 6 votes |
public static Initializable getInitializable(String viewName) throws IOException { FXMLLoader loader = new FXMLLoader(); // 创建对象 loader.setBuilderFactory(new JavaFXBuilderFactory()); // 设置BuilderFactory loader.setLocation(GameView.class.getResource(viewName + ".fxml")); // 设置路径基准 try { InputStream in = GameView.class.getResourceAsStream(viewName + ".fxml"); AnchorPane page = (AnchorPane) loader.load(in); // 对象方法的参数是InputStream,返回值是Object Scene scene = new Scene(page, 800, 600); Stage stage = new Stage(); stage.setScene(scene); stage.sizeToScene(); return (Initializable) loader.getController(); // 可以得到Controller } finally { in.close(); return null; } }
Example #2
Source File: SceneManager.java From CustomStage with Apache License 2.0 | 5 votes |
/** * Adds the specific view and its controller to the map. * * @param id name which you will access this scene later on * @param controller controller of the specific view (this must implement Initializable) * @param scene parent node retrieved from fxmlLoader.load() * @param <T> Class of the Controller (extends Initializable) * @param <K> Class of the view (extends Node) */ public <T extends Initializable,K extends Node> void addScene(String id, K scene, T controller){ sceneMap.put( id, new SceneMapper<T,K>( controller, scene ) ); }
Example #3
Source File: SceneManager.java From CustomStage with Apache License 2.0 | 2 votes |
/** * @param id id which is used to map the scene * @param <T> Class of the view (extends Node) * @return the controller of the specific view */ public <T extends Initializable> T getController(String id ){ return (T) sceneMap.get(id).getController(); }