التعليم السعودي
طريقة إنشاء JRadioButton
طريقة إنشاء JRadioButton
طريقة إنشاء JRadioButton
طريقة إنشاء JRadioButton
طريقة إنشاء JRadioButton
طريقة إنشاء JRadioButton
طريقة إنشاء JRadioButton
مثال
- import javax.swing.JFrame;
- import javax.swing.JRadioButton;
- publicclass Main {
- publicstaticvoidmain(String[] args){
- JFrame frame = newJFrame(“JRadioButton demo”); // أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس
- frame.setSize(300, 250); // هنا قمنا بتحديد حجم النافذة. عرضها 300 و طولها 250
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // هنا جعلنا زر الخروج من النافذة يغلق البرنامج
- frame.setLayout(null); // في النافذة بنفسنا Radio Button لذلك سنقوم بتحديد مكان الـ Layout Manager أي لم نستخدم أي null هنا وضعنا
- JRadioButton radioButton = newJRadioButton(“Radio Button”, true); // و قمنا بإختياره أيضاً Radio Button أي قمنا بإنشاء JRadioButton هنا أنشأنا كائن من الكلاس
- radioButton.setBounds(40, 40, 100, 30); // frame في الـ Radio Button هنا قمنا بتحديد حجم و موقع الـ
- frame.add(radioButton); // frame في الـ radioButton هنا أضفنا الـ
- frame.setVisible(true); // هنا جعلنا النافذة مرئية
- }
- }
•ستظهر لك النافذة التالية عند التشغيل.
المصدر: طريقة إنشاء JRadioButton – المناهج السعودية