Programming Basics SQL HTML CSS JavaScript Python C++ Java JavaFX Swing Problem Solving English English Conversations Computer Fundamentals Learn Typing

JavaFXطريقة إنشاء RadioButton و إضافته في النافذة

المثال التالي يعلمك طريقة إنشاء كائن من الكلاس RadioButton و إضافته في النافذة.


مثال

Main.java
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage stage) {
// يمثل الزر الذي نريد إضافته في النافذة RadioButton هنا قمنا بإنشاء كائن من الكلاس
RadioButton radioButton = new RadioButton("RadioButton");
// في النافذة radioButton هنا قمنا بتحديد مكان ظهور الكائن
radioButton.setTranslateX(155);
radioButton.setTranslateY(105);
// في النافذة Root Node لأننا ننوي جعله الـ Group هنا قمنا بإنشاء كائن من الكلاس
Group root = new Group();
// root في الكائن radioButton هنا قمنا بإضافة الكائن
root.getChildren().add(radioButton);
// فيها و تحديد حجمها Node كأول root هنا قمنا بإنشاء محتوى النافذة مع تعيين الكائن
Scene scene = new Scene(root, 400, 250);
// هنا وضعنا عنوان للنافذة
stage.setTitle("JavaFX RadioButton");
// أي وضعنا محتوى النافذة الذي قمنا بإنشائه للنافذة .stage في كائن الـ scene هنا وضعنا كائن الـ
stage.setScene(scene);
// هنا قمنا بإظهار النافذة
stage.show();
}
// هنا قمنا بتشغيل التطبيق
public static void main(String[] args) {
launch(args);
}
}
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.RadioButton; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage stage) { // يمثل الزر الذي نريد إضافته في النافذة RadioButton هنا قمنا بإنشاء كائن من الكلاس RadioButton radioButton = new RadioButton("RadioButton"); // في النافذة radioButton هنا قمنا بتحديد مكان ظهور الكائن radioButton.setTranslateX(155); radioButton.setTranslateY(105); // في النافذة Root Node لأننا ننوي جعله الـ Group هنا قمنا بإنشاء كائن من الكلاس Group root = new Group(); // root في الكائن radioButton هنا قمنا بإضافة الكائن root.getChildren().add(radioButton); // فيها و تحديد حجمها Node كأول root هنا قمنا بإنشاء محتوى النافذة مع تعيين الكائن Scene scene = new Scene(root, 400, 250); // هنا وضعنا عنوان للنافذة stage.setTitle("JavaFX RadioButton"); // أي وضعنا محتوى النافذة الذي قمنا بإنشائه للنافذة .stage في كائن الـ scene هنا وضعنا كائن الـ stage.setScene(scene); // هنا قمنا بإظهار النافذة stage.show(); } // هنا قمنا بتشغيل التطبيق public static void main(String[] args) { launch(args); } }

ستظهر لك النافذة التالية عند التشغيل.

طريقة إضافة RadioButton في javafx