1
我在屏幕上顯示我的主菜單時出現問題。我看不出問題在哪裏。它正在顯示的是一個空白的JFrame窗口。它沒有顯示我的面板上的按鈕。Java GUI:按鈕控件不可見
主類:
public class Main {
public static void main(String[] args) {
GUIView gui = new GUIView();
}
}
GUIView類別:
import javax.swing.*;
import java.awt.*;
public class GUIView {
protected JFrame frame;
public GUIView() {
frame = new JFrame("Test");
frame.setVisible(true);
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
MainMenu的類別:
import javax.swing.*;
import java.awt.*;
public class MainMenu extends GUIView {
private JButton b1, b2, b3;
private JPanel panel;
public MainMenu() {
GridBagLayout gridbag = new GridBagLayout();
b1 = new JButton();
b2 = new JButton();
b3 = new JButton();
//Button Settings;
b1.setText("Administrator");
b2.setText("Program Leader");
b3.setText("Lecturer");
//Panel Settings
panel = new JPanel();
panel.setLayout(gridbag);
panel.add(b1);
panel.add(b2);
panel.add(b3);
panel.setVisible(true);
super.frame.add(panel);
}
}
你正在構建GuiView而不是MainMenu –