我写这个是为了好玩,这不是功课,所以请尽我所能帮助我。我想制作一个"骰子"吐出各种滑雪技巧,你可以做,我不能让我的gui上来或工作。
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);
这是我的主要方法。
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++){
}
}
我在这三行没有错误
this.add(panel1);
this.pack();
this.setVisible(true);
我知道现在已经搞砸了,我从一个旧项目中获取了代码,但我忘记了我是如何使用它的。感谢您的帮助,非常感谢
答案 0 :(得分:0)
需要扩展SkiDice20。之后,它起作用了。