我一直在尝试用Java重新创建它:http://imgur.com/pjt7SMZ
这是我到目前为止的代码:
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;
private JButton readFileButton;
private JButton exitButton;
private JButton statsButton;
private JButton clearButton;
private JButton helpButton;
private JLabel headerLabel;
public Display() {
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setResizable(false);
setTitle("CSCE155A Course Offering Viewer");
setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new BorderLayout());
JPanel header = new JPanel(new GridLayout(1, 1, 5, 5));
headerLabel = new JLabel("CSCE155A Course Offering Viewer");
header.add(headerLabel);
}
public static void main(String[] args) {
Display frame = new Display();
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
}
}
我的问题在于JPanel
。按照我们的指示,我们假设在BorderLayout
内部使用GridLayout
,但每当我运行代码时都没有任何反应。 JPanel
甚至是最好的方法吗?现在我只是想让标题工作。
答案 0 :(得分:2)
根据您的设计,您不应在JLabel
上添加JPanel
。在headerLabel
之上添加JFrame
并对齐文本CENTER
。
headerLabel = new JLabel("CSCE155A Course Offering Viewer",JLabel.CENTER);
add(headerLabel,BorderLayout.NORTH);// Add it with JFrame.