我一直有麻煩重塑這種GUI:的JPanel與GridLayout的
我們被告知使用BorderLayout的每個部分內網格。我一直在努力領導標題工作(類名和人名的GUI頂部廣場),但我似乎無法得到任何東西顯示。這是我到目前爲止:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Display extends JFrame implements ActionListener {
private static final int FRAME_WIDTH = 400;
private static final int FRAME_HEIGHT = 350;
private static final int FRAME_X_ORIGIN = 100;
private static final int FRAME_Y_ORIGIN = 75;
public static void main(String[] args) {
Display frame = new Display();
frame.setVisible(true);
}
public Display() {
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setResizable(false);
setLayout(null);
setTitle("CSCE155A Course Offering Viewer");
setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
setDefaultCloseOperation(EXIT_ON_CLOSE);
// header
JPanel header = new JPanel();
header.setLayout(new GridLayout(2, 1));
header.setSize(380, 50);
header.setLocation(0, 0);
header.setBorder(BorderFactory.createLineBorder(Color.BLACK));
header.add(new JLabel("CSCE155A Course Offering Viewer"));
header.add(new JLabel("First Last"));
}
public void actionPerformed(ActionEvent event) {
}
}
唯一顯示的是窗口裏面沒有任何東西。