如何在Java中使用GridLayout?

时间:2013-10-31 06:27:23

标签: java swing layout jlabel grid-layout

我在名为PlayFrame的类中使用此代码:

public void construct(FieldPanel fPanel){
    this.setTitle("Play");
    Dimension dimension = new Dimension(1200,600);
    this.setSize(dimension);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.pack();
    GridLayout gLayout = new GridLayout();
    this.setLayout(layout);
    score.setText("Score: " + pField.scoreValue);
//      this.add(score);
//      this.add(scoreList);
//      this.add(status);

正如您所看到的,我尝试创建一个新的GridLayout对象,但我不确定如何使用它来显示必要的组件。我需要一个左上角有一个大面板的布局,右上角有一个得分列表面板,左下角有一个小的状态标签,右下角有一个小的得分标签。所以,我有一些注意事项,因为我不确定它们是否有效或者确实是它们的作用。如何让PlayFrame显示fPanel,两个标签和另一个面板,我需要它们在框架中排列?我只需要知道如何创建和使用GridLayout对象。感谢。

这就是窗口的样子:

________________________________________________________________________________
|Play                                                                     - 0 x |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Score List:     | 
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Mario: 100      | 
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Luigi: 50       |        
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waluigi: 20     | 
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Wario: 10       |       
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                 | 
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                 |       
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                 | 
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                 |       
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                 | 
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                 |       
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                 | 
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                 |    
|Status: Ready!                                                       Score: 30 |
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

百分比符号只是游戏发生的屏幕。我希望这会有所帮助。

1 个答案:

答案 0 :(得分:0)

如果使用eclipse,我发现Window Builder对于创建GUI非常有用。否则,正如其他人所说,甲骨文的网站是一个很好的起点。