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

Swingطريقة ترتيب محتوى الـ JFrame كجدول يتألف من أسطر و أعمدة متساوية الحجم بواسطة االكلاس GridLayout

المثال التالي يعلمك طريقة ترتيب محتوى الـ Frame في سطر واحد يتألف من أعمدة متساوية الحجم بواسطة الكلاس GridLayout.


مثال

Main.java
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.GridLayout;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("GridLayout demo"); // أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس
frame.setSize(400, 300); // هنا قمنا بتحديد حجم النافذة. عرضها 400 و طولها 300
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // هنا جعلنا زر الخروج من النافذة يغلق البرنامج
frame.setLayout(new GridLayout()); // لترتيب الأشياء التي نضيفها بداخلها GridLayout هنا جعلنا النافذة تستخدم الـ
// هنا قمنا بتعريف 9 أزرار
JButton b1 = new JButton("1");
JButton b2 = new JButton("2");
JButton b3 = new JButton("3");
JButton b4 = new JButton("4");
JButton b5 = new JButton("5");
JButton b6 = new JButton("6");
JButton b7 = new JButton("7");
JButton b8 = new JButton("8");
JButton b9 = new JButton("9");
// هنا قمنا بإضافة الأزرار في النافذة
frame.add(b1);
frame.add(b2);
frame.add(b3);
frame.add(b4);
frame.add(b5);
frame.add(b6);
frame.add(b7);
frame.add(b8);
frame.add(b9);
// هنا جعلنا النافذة مرئية
frame.setVisible(true);
}
}
import javax.swing.JFrame; import javax.swing.JButton; import java.awt.GridLayout; public class Main { public static void main(String[] args) { JFrame frame = new JFrame("GridLayout demo"); // أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس frame.setSize(400, 300); // هنا قمنا بتحديد حجم النافذة. عرضها 400 و طولها 300 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // هنا جعلنا زر الخروج من النافذة يغلق البرنامج frame.setLayout(new GridLayout()); // لترتيب الأشياء التي نضيفها بداخلها GridLayout هنا جعلنا النافذة تستخدم الـ // هنا قمنا بتعريف 9 أزرار JButton b1 = new JButton("1"); JButton b2 = new JButton("2"); JButton b3 = new JButton("3"); JButton b4 = new JButton("4"); JButton b5 = new JButton("5"); JButton b6 = new JButton("6"); JButton b7 = new JButton("7"); JButton b8 = new JButton("8"); JButton b9 = new JButton("9"); // هنا قمنا بإضافة الأزرار في النافذة frame.add(b1); frame.add(b2); frame.add(b3); frame.add(b4); frame.add(b5); frame.add(b6); frame.add(b7); frame.add(b8); frame.add(b9); // هنا جعلنا النافذة مرئية frame.setVisible(true); } }

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

طريقة ترتيب محتوى ال JFrame في سطر واحد يتألف من أعمدة متساوية الحجم بواسطة الكلاس GridLayout في جافا

الدورات

أدوات مساعدة

أقسام الموقع

دورات
مقالات كتب مشاريع أسئلة