문제

Im writing this for fun, this is not homework so please help me all you can. I am trying to make a "dice" that spits out various ski tricks that you can do and i cannot get my gui to come up or work.

public SkiDice20(){


this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel1 = new JPanel();
panel1.setLayout(new GridBagLayout());
addItem(panel1, new JLabel("Name: "), 0, 0, 1, 1, GridBagConstraints.EAST);

addItem(panel1, newName, 1, 0, 2, 1, GridBagConstraints.WEST);

System.out.print(newName.getText());
Box slayBox = Box.createVerticalBox();

slayGroup.add(jump);
slayGroup.add(rail);
slayGroup.add(slope);
slayBox.add(jump);
slayBox.add(rail);
slayBox.add(slope);
slayBox.setBorder(BorderFactory.createTitledBorder("What are you Slaying?"));
addItem(panel1, slayBox, 0, 3, 1, 1, GridBagConstraints.NORTH);

Box skillBox = Box.createVerticalBox();


skillGroup.add(gaper);
skillGroup.add(nser);
skillGroup.add(am);
skillGroup.add(pro);
skillBox.add(gaper);
skillBox.add(nser);
skillBox.add(am);
skillBox.add(pro);
skillBox.setBorder(BorderFactory.

createTitledBorder("Skill?"));
addItem(panel1, skillBox, 1, 3, 1, 1, GridBagConstraints.NORTH);

Box buttonBox = Box.createHorizontalBox();
buttonBox.add(okButton);
buttonBox.add(Box.createHorizontalStrut(20));
buttonBox.add(completeButton);
addItem(panel1, buttonBox, 2, 4, 1, 1, GridBagConstraints.NORTH);

this.add(panel1);
this.pack();
this.setVisible(true);

And this is my main method.

public static void main(String[] args) {

    String input = JOptionPane.showInputDialog ( "Number of people Skiing?" );
    numberOfPeople = Integer.parseInt(input);
    new SkiDice20();
    checkSelection();

    for (int i = 0; i < numberOfPeople; i++){

    }

}

I am getting an error on these three lines and nothing else

this.add(panel1);
this.pack();
this.setVisible(true);

I know the cooardinates are screwed up right now, i took the code from an old project that i did but i forgot how i got this to work. Thank you for any help it is greatly appreciated

도움이 되었습니까?

해결책

Needed to extend SkiDice20. After that it worked.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top