البرمجة

بناء واجهة معقدة باستخدام Java Swing

To achieve the layout you described in Java Swing, you can use nested layouts. Here’s an example code snippet that demonstrates how you can create a frame with the layout you described:

java
import javax.swing.*; import java.awt.*; public class ComplexFrameExample { public static void main(String[] args) { JFrame frame = new JFrame("Complex Frame Example"); frame.setSize(800, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel mainPanel = new JPanel(new BorderLayout()); // Image on top ImageIcon imageIcon = new ImageIcon("path_to_your_image.jpg"); JLabel imageLabel = new JLabel(imageIcon); mainPanel.add(imageLabel, BorderLayout.NORTH); // 16 little images divided in 4 groups JPanel imagesPanel = new JPanel(new GridLayout(4, 4)); for (int i = 0; i < 16; i++) { JLabel image = new JLabel("Image " + i); imagesPanel.add(image); } mainPanel.add(imagesPanel, BorderLayout.CENTER); // 4 panels with horizontal scrollable images JPanel scrollableImagesPanel = new JPanel(new GridLayout(1, 4)); for (int i = 0; i < 4; i++) { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(200, 100)); panel.add(new JScrollPane(new JTextArea("Scrollable Image " + i))); scrollableImagesPanel.add(panel); } mainPanel.add(scrollableImagesPanel, BorderLayout.SOUTH); // Add main panel to frame frame.add(mainPanel); frame.setVisible(true); } }

This code creates a frame with the specified layout. You can further customize the sizes, images, and text according to your requirements.

المزيد من المعلومات

لبناء الواجهة التي وصفتها في Java Swing، يمكنك استخدام مجموعة متنوعة من المكونات وتخطيطات الإطارات. هنا هو الرمز الكامل لبناء الواجهة المحددة:

java
import javax.swing.*; import java.awt.*; public class ComplexFrameExample { public static void main(String[] args) { JFrame frame = new JFrame("Complex Frame Example"); frame.setSize(800, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel mainPanel = new JPanel(new BorderLayout()); // Image on top ImageIcon imageIcon = new ImageIcon("path_to_your_image.jpg"); JLabel imageLabel = new JLabel(imageIcon); mainPanel.add(imageLabel, BorderLayout.NORTH); // 16 little images divided in 4 groups JPanel imagesPanel = new JPanel(new GridLayout(4, 4)); for (int i = 0; i < 16; i++) { JLabel image = new JLabel("Image " + i); imagesPanel.add(image); } mainPanel.add(imagesPanel, BorderLayout.CENTER); // 4 panels with horizontal scrollable images JPanel scrollableImagesPanel = new JPanel(new GridLayout(1, 4)); for (int i = 0; i < 4; i++) { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(200, 100)); panel.add(new JScrollPane(new JTextArea("Scrollable Image " + i))); scrollableImagesPanel.add(panel); } mainPanel.add(scrollableImagesPanel, BorderLayout.SOUTH); // 2 panels with horizontal scrollable images and JList JPanel bottomPanel = new JPanel(new GridLayout(1, 2)); for (int i = 0; i < 2; i++) { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(200, 100)); panel.add(new JScrollPane(new JTextArea("Scrollable Image " + i))); bottomPanel.add(panel); } // JList String[] data = {"Item 1", "Item 2", "Item 3", "Item 4"}; JList list = new JList<>(data); bottomPanel.add(new JScrollPane(list)); mainPanel.add(bottomPanel, BorderLayout.SOUTH); // 4 panels with text rows JPanel textPanels = new JPanel(new GridLayout(1, 4)); for (int i = 0; i < 4; i++) { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(200, 100)); panel.add(new JTextArea("Text Row " + i)); textPanels.add(panel); } mainPanel.add(textPanels, BorderLayout.SOUTH); // Add main panel to frame frame.add(mainPanel); frame.setVisible(true); } }

هذا الرمز يستخدم JPanel لبناء هيكل الإطار، و JLabel لعرض الصور، و JScrollPane لجعل النص قابل للتمرير إذا كان طويلاً، و JList لعرض قائمة نصية. تستطيع تعديل الأبعاد والمحتوى لتناسب احتياجاتك.

زر الذهاب إلى الأعلى