آموزش مقدماتی javafx | آموزش JavaFX switch scenes

JavaFX یک پلتفرم برای خلق وب‌اپلیکیشن‌های غنی است. منظور از وب‌اپلیکیشن‌های غنی آن اپ‌هایی هستند که قابلیت‌ها و همچنین تجربه کاربری مشابه اپلیکیشن‌های دسکتاپ را عرضه می‌کند و در این ویدیو یک مثال برای شما آورده شده است.//--------------------------------Main.java--------------------------------------package application; import javafx.application.Application;import javafx.fxml.FXMLLoader;import javafx.stage.Stage;import javafx.scene.Parent;import javafx.scene.Scene;public class Main extends Application { @Override public void start(Stage stage) { try { Parent root = FXMLLoader.load(getClass().getResource("Scene1.fxml")); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { launch(args); }}//---------------------------------SceneController.java---------------------------------------package application;import java.io.IOException;import javafx.event.ActionEvent;import javafx.fxml.FXMLLoader;import javafx.scene.Node;import javafx.scene.Parent;import javafx.scene.Scene;import javafx.stage.Stage;public class SceneController { private Stage stage; private Scene scene; private Parent root; public void switchToScene1(ActionEvent event) throws IOException { root = FXMLLoader.load(getClass().getResource("Scene1.fxml")); stage = (Stage)((Node)event.getSource()).getScene().getWindow(); scene = new Scene(root); stage.setScene(scene); stage.show(); } public void switchToScene2(ActionEvent event) throws IOException { Parent root = FXMLLoader.load(getClass().getResource("Scene2.fxml")); stage = (Stage)((Node)event.getSource()).getScene().getWindow(); scene = new Scene(root); stage.setScene(scene); stage.show(); }}//------------------------------------------------------------------------------------------------
ویدیوهای مرتبط
ویدیوهای جدید