java - 尝试制作 GUI,找不到显示的符号?

标签 java swing user-interface jpanel

该程序的目标是用 Java 创建您自己的图形用户界面 (GUI)。使用至少 4 个不同的 GUI 组件(按钮、组合框、支票簿、文本字段……)。我正在尝试制作 GUI,但在尝试为 GUI 制作子面板时不断收到错误消息?具体来说,它从我的代码中的 panel2 开始。谢谢。

import javax.swing.*;
public class PTtestGUI {
    public static void main(String[] args) {
       //Declare labels
        JLabel ranklabel = new JLabel("Rank"); 
        JLabel firstLabel = new JLabel("First Name");
        JLabel middleInitialLabel = new JLabel("Middle Initial");
        JLabel lastLabel = new JLabel("Last Name"); 
        JLabel pushUp = new JLabel("Number of Push-ups");
        JLabel sitUp = new JLabel("Number of Sit-ups");
        JLabel run = new JLabel("Run time");

        //Declare TextFields
        JTextField lastName = new JTextField("Enter Last Name");
        JTextField firstName = new JTextField("Enter First Name");
        JTextField middleInitial = new JTextField("Enter Middle Initial");

        //Declare radio button
        JRadioButton army = new JRadioButton("ARMY");
        JRadioButton navy = new JRadioButton("NAVY");
        JRadioButton marine = new JRadioButton("MARINE");
        JRadioButton airForce = new JRadioButton("AIR FORCE");

        //Declare Combo box
        JComboBox rank = new JComboBox(new String[] {"PVT", "PV2", "PFC", 
            "SPC", "SGT", "SSG", "SFC", "MSG", "CSM"});

        //Declare buttons
        JButton jbtOK = new JButton("Calculate APFT");
        JButton jbtCancel = new JButton("Cancel");     

        // Create a primary panel that's arranged vertically
        JPanel panel1 = new JPanel();
        panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));

        Jpanel panel2 = new Jpanel();
        panel2.add(ranklabel);//Add the label rank to the panel
        panel2.add(rank);//Add the label rank to the panel
        panel2.add(lastLabel);//Add the label rank to the panel
        panel2.add(lastName);//Add the label rank to the panel
        panel2.add(firstLabel);//Add the label rank to the panel
        panel2.add(firstName);//Add the label rank to the panel
        panel2.add(middleInitialLabel);//Add the label rank to the panel
        panel2.add(middleInitial);//Add the label rank to the panel

        Jpanel panel3 = new Jpanel();//What branch of the military the user is in
        panel3.add(army);//Add the label rank to the panel
        panel3.add(navy);//Add the label rank to the panel
        panel3.add(marine);//Add the label rank to the panel
        panel3.add(airForce);//Add the label rank to the panel

        Jpanel panel4 = new Jpanel();//How many repititions did the user get on the PT test
        panel4.add(pushUp);//Add the label rank to the panel
        panel4.add(sitUp);//Add the label rank to the panel
        panel4.add(run);//Add the label rank to the panel

        Jpanel panel5 = new Jpanel();//offers the user the ability to calculate or cancel the program
        panel5.add(jbtOK);//Add the label rank to the panel
        panel5.add(jbtCancel);//Add the label rank to the panel

        // Add the sub-panels to the primary panel
        panel1.add(panel2);
        panel1.add(panel3);
        panel1.add(panel4);
        panel1.add(panel5);


        //Displays main frame according to attributes set
        JFrame displayFrame = new JFrame();
        displayFrame.setTitle("PT Test Calculator");
        displayFrame.setSize(1000, 300);
        displayFrame.setLocation(300, 150);
        displayFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        displayFrame.setVisible(true);
        displayFrame.add(panel1);

    }//end main
}//end class

最佳答案

Java 区分大小写。例如,您需要将所有出现的 Jpanel 替换为 JPanel

JPanel panel2 = new JPanel();
 ^                   ^

关于java - 尝试制作 GUI,找不到显示的符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19439054/

相关文章:

java - 我想在运行时在 java 中更改属性名称

java - Java发送邮件报错

ios - 带圆角半径的渐变 UIButton 边框

java - 为什么在 JFrame.setVisible(true) 之后调用 JFrame.pack() 会影响 JFrame 显示的位置?

java - JCheckBox 在选择时不更新

java - Qt Jambi 与 SWT 的跨平台 GUI 开发

python - 我无法将我的 pygame 游戏链接到我的 tkinter GUI

java - 在 SWT 中包装 List 的内容

java - Spring Data Neo4j Repository Composition 错误 : No property XXXX found for type YYYY

java - 在 JTable 中获取选定的单元格值