Swingطريقة ترتيب محتوى الـ JFrame بواسطة الكلاس BorderLayout
المثال التالي يعلمك طريقة ترتيب محتوى الـ Frame بواسطة الكلاس BorderLayout.
مثال
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("BorderLayout demo"); // أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس
frame.setSize(400, 300); // هنا قمنا بتحديد حجم النافذة. عرضها 400 و طولها 300
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // هنا جعلنا زر الخروج من النافذة يغلق البرنامج
frame.setLayout(new BorderLayout()); // لترتيب الأشياء التي نضيفها بداخلها BorderLayout هنا جعلنا النافذة تستخدم الـ
// هنا قمنا بتعريف 5 أزرار
JButton b1 = new JButton("North");
JButton b2 = new JButton("South");
JButton b3 = new JButton("East");
JButton b4 = new JButton("West");
JButton b5 = new JButton("Center");
// هنا وضع كل زر في مكان مختلف في النافذة
frame.add(b1, BorderLayout.NORTH);
frame.add(b2, BorderLayout.SOUTH);
frame.add(b3, BorderLayout.EAST);
frame.add(b4, BorderLayout.WEST);
frame.add(b5, BorderLayout.CENTER);
// هنا جعلنا النافذة مرئية
frame.setVisible(true);
}
}
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("BorderLayout demo"); // أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس
frame.setSize(400, 300); // هنا قمنا بتحديد حجم النافذة. عرضها 400 و طولها 300
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // هنا جعلنا زر الخروج من النافذة يغلق البرنامج
frame.setLayout(new BorderLayout()); // لترتيب الأشياء التي نضيفها بداخلها BorderLayout هنا جعلنا النافذة تستخدم الـ
// هنا قمنا بتعريف 5 أزرار
JButton b1 = new JButton("North");
JButton b2 = new JButton("South");
JButton b3 = new JButton("East");
JButton b4 = new JButton("West");
JButton b5 = new JButton("Center");
// هنا وضع كل زر في مكان مختلف في النافذة
frame.add(b1, BorderLayout.NORTH);
frame.add(b2, BorderLayout.SOUTH);
frame.add(b3, BorderLayout.EAST);
frame.add(b4, BorderLayout.WEST);
frame.add(b5, BorderLayout.CENTER);
// هنا جعلنا النافذة مرئية
frame.setVisible(true);
}
}
ستظهر لك النافذة التالية عند التشغيل.