试图制作GUI,找不到符号?

时间:2013-10-17 23:30:33

标签: 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

1 个答案:

答案 0 :(得分:3)

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

JPanel panel2 = new JPanel();
 ^                   ^