Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java中带有容器的空白窗口_Java_Window - Fatal编程技术网

java中带有容器的空白窗口

java中带有容器的空白窗口,java,window,Java,Window,我正在编写一个程序,该程序应该有一个窗口,其中包含各种组件,所有组件都在容器中分组。单击Get Started按钮时,应该会打开另一个窗口,其中包含GlobalTeangerProject类中case2:下列出的容器。问题是当你点击这个按钮时,它会弹出一个新窗口,但是窗口是完全空白的。有人知道它出了什么问题吗?源代码是: import java.awt.*; import java.awt.event.*; import java.awt.geom.*; public class Global

我正在编写一个程序,该程序应该有一个窗口,其中包含各种组件,所有组件都在容器中分组。单击Get Started按钮时,应该会打开另一个窗口,其中包含GlobalTeangerProject类中case2:下列出的容器。问题是当你点击这个按钮时,它会弹出一个新窗口,但是窗口是完全空白的。有人知道它出了什么问题吗?源代码是:

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;

public class GlobalTeenagerProject extends Frame implements ActionListener, ItemListener{

  private static final long serialVersionUID = 1L;
  int ACTSATOp;
  TextField ApNumberField=new TextField(20),
            ApScoreField=new TextField(20),
            ACTField=new TextField(20),
            SATField=new TextField(20),
            leadershipNumberField=new TextField(20),
            leadershipHoursField=new TextField(20), 
            leadershipLengthField =new TextField(20),
            serviceHoursField = new TextField(20),
            GPAField = new TextField(20);
  Label ApNumberLabel = new Label ("Please enter the number of AP tests you have taken");
  Label APScoreLabel = new Label ("Please input your first AP test score with no decimal point");
  Label leadershipNumberLabel = new Label ("Please input the number of Leadership positions you have held");
  Label serviceHoursLabel =  new Label ("Please enter the number of community service hours you have done since starting high school");
  Label leadershipLengthLabel = new Label ("How long did you serve in your 1st leadership position");
  Label GPALabel = new Label ("What is your GPA?");

  Button submitButton = new Button ("Submit");
  Button getStartedButton = new Button ("Get Started");
  Button seeStatsButton = new Button("Compare yourself");
  Button goButton = new Button("Go");

  CheckboxGroup ACTSATgroup;
  Checkbox ACTBox = new Checkbox ("ACT",false,ACTSATgroup);
  Checkbox SATBox = new Checkbox("SAT", false, ACTSATgroup);
  Checkbox hiddenBox = new Checkbox("",true,ACTSATgroup);
  Checkbox bothBox = new Checkbox("Both", false, ACTSATgroup);

  double ACT, SAT, serviceHours, leadershipNumber, LNumberLength, APLength, GPAnumber;
  double leadershipLengthArray[], APTestNumber[], ApScore[];

  Button button[] = {submitButton, getStartedButton, seeStatsButton, goButton};
  Panel ACTSATpanel = new Panel();
  Panel GPAPanel = new Panel();
  Panel APpanel = new Panel();
  Panel servicePanel = new Panel();
  Panel leadershipPanel = new Panel();
  Panel buttonPanel = new Panel();
  Panel mainPanel = new Panel();

  int j=0;

  public GlobalTeenagerProject(int type) {
    switch(type){
      case 1:
        this.setLayout(new BorderLayout());

        buttonPanel.setLayout(new GridLayout(2,1,10,10));
        add(buttonPanel,BorderLayout.CENTER);

        buttonPanel.add(button[1]);
        button[1].addActionListener(this);

        buttonPanel.add(button[2]);
        button[2].addActionListener(this);
        addWindowListener(
          new WindowAdapter(){
            public void windowClosing(WindowEvent e){
              System.exit(0);
            }
          }
        );
        break;

      case 2:
        this.setLayout(new GridLayout(6,1,10,10));
        ACTSATpanel.setLayout(new GridLayout(2,3,10,10));
        APpanel.setLayout(new GridLayout(2,2,10,10));
        servicePanel.setLayout(new GridLayout(5,2,10,10));
        leadershipPanel.setLayout(new GridLayout(1,2,10,10));
        GPAPanel.setLayout(new FlowLayout());
        buttonPanel.setLayout (new GridLayout (2,1,10,10));

        GPAPanel.add(GPALabel);
        GPAPanel.add(GPAField);
        ACTSATpanel.add(ACTBox);
        ACTSATpanel.add(SATBox);
        APpanel.add(ApNumberLabel);
        APpanel.add(ApNumberField);
        APpanel.add(APScoreLabel);
        APpanel.add(ApScoreField);

        servicePanel.add(serviceHoursLabel);
        servicePanel.add(serviceHoursField);

        leadershipPanel.add(leadershipNumberLabel);
        leadershipPanel.add(leadershipNumberField);
        leadershipPanel.add(goButton);

        goButton.addActionListener(this);
        buttonPanel.add(submitButton);
        submitButton.addActionListener(this);
        addWindowListener(
          new WindowAdapter(){
            public void windowClosing(WindowEvent e){
              System.exit(0);
            }
          }
        );
        break;

      case 3:
        // put in graphing component
        break;
    }
  }

  public static void main(String[]args){
    GlobalTeenagerProject k = new GlobalTeenagerProject(1);
    k.setVisible(true);
    k.setBounds(200, 200, 600, 600);
    k.setTitle("CollegeConnections");
  }

  public void actionPerformed(ActionEvent e) {
    if(e.getSource()== button[1]){
      GlobalTeenagerProject i = new GlobalTeenagerProject(2);
      i.setVisible(true);
      i.setBounds(200,200, 600, 600);
    }
    else{
      if(e.getSource()==button[0]){
        remove(GPAPanel);
        remove(ACTSATpanel);
        remove(APpanel);
        remove(servicePanel);
        remove(leadershipPanel);

        buttonPanel.remove(submitButton);
        this.setLayout(new BorderLayout());
        buttonPanel.setLayout(new GridLayout(2,1,10,10));
        buttonPanel.add(getStartedButton);
        buttonPanel.add(seeStatsButton);
        add(buttonPanel,BorderLayout.CENTER);
      }
      else{
        if(e.getSource()=="Submit"){
          GlobalTeenagerProject j= new GlobalTeenagerProject(3);
          j.setVisible(true);
          j.setBounds(200, 200, 600, 800);
        }
        else{
          if(e.getSource()==button [3]){
            int leadershipNumber = 0;
            leadershipPanel.setLayout(null);
          }
        }
      }
    }
  }

  public void itemStateChanged(ItemEvent f) {
    if (ACTBox.getState()){
      ACTSATOp = 1;
      ACTSATpanel.add(ACTField);
    }
    else{
      if(SATBox.getState()){
        ACTSATOp =2;
        ACTSATpanel.add(SATField);
      }
      else{
        if(bothBox.getState()){
          ACTSATOp =3;
          ACTSATpanel.add(ACTField);
          ACTSATpanel.add(SATField);
        }
      }
    }
  }
}

你试过调整窗口大小吗?如果组件在调整其大小后出现,则意味着您必须在程序结束时(创建窗口时)调用方法
which_FRAME.repaint()

我想您忘记了将所有面板添加到框架中。尝试将此添加到您的代码中:

    this.add(ACTSATpanel);
    this.add(APpanel);
    this.add(servicePanel);
    this.add(leadershipPanel);
    this.add(GPAPanel);
    this.add(buttonPanel);

很高兴这有帮助。如果您满意,请接受答案。谢谢。