为什么我的Applet没有显示我的面板,按钮,文本字段和文本区域?

时间:2016-02-24 11:18:24

标签: java applet jpanel jbutton

我使用这些组件设计了这个applet但是当我运行applet时,一切都是空白的。在main方法中,我使用2个选项卡初始化窗格。此CreatePanel是需要显示的选项卡之一。谢谢!

public CreatePanel(Vector projectList, ProjectSpendingPanel spendingPanel)
  {
    this.projectList = projectList;
    this.spendingPanel = spendingPanel;

    //organize components here

    //Labels for the Name, Number, Location, Funding, 

    JLabel name = new JLabel("Project Name");
    JLabel number = new JLabel("Project Number");
    JLabel location = new JLabel("Project Location");
    JLabel funding = new JLabel("Initial Funding");

    //Text fields for entering input
    JTextField nameField = new JTextField();
    JTextField numberField = new JTextField();
    JTextField locationField = new JTextField();
    JTextField fundingField = new JTextField();

    //creating panels and a text area putting them inside one another
    JPanel panel1 = new JPanel();
    panel1.setLayout(new GridLayout(1,2));
    JPanel panel2 = new JPanel();
    panel2.setLayout(new GridLayout(2,1));
    panel1.add(panel2);
    JTextArea area1 = new JTextArea();
    panel1.add(area1);
    JPanel panel3 = new JPanel(new GridLayout(4,2));
    JPanel panel4 = new JPanel(new BorderLayout());
    panel2.add(panel3);
    panel2.add(panel4);

    //adding things to panel3
    panel3.add(name);
    panel3.add(nameField);
    panel3.add(number);
    panel3.add(numberField);
    panel3.add(location);
    panel3.add(locationField);
    panel3.add(funding);
    panel3.add(fundingField);

    //Creating a button and adding it to panel4
    JButton button1 = new JButton("Create a Project");
    panel4.add(button1,BorderLayout.NORTH);


  }

0 个答案:

没有答案