0

GUIビルダーを使用して、JFrameを含むシンプルなものを作成していますJPanel. 乱数のJButtons をパネルに追加したいのですが、JPanel 用に独自のコードを作成せずにこれを行うことは可能ですか? Swing レイアウトが苦手なので質問します。

メインクラス:

public static void main( String[] args )
{         
    int buttonCount = new Random().nextInt(5)+1;
    JFoo foo = new JFoo(buttonCount);
    foo.setVisible(true);
}

JFoo クラス:

public class JFoo extends javax.swing.JFrame {
int buttonCount;

public JFoo() {
    initComponents();
}
public JFoo(int buttonCount) {
    this.buttonCount = buttonCount;
    initComponents();
    buttonCountLabel.setText("Button Count: "+buttonCount);
}

private void initComponents() {
    //generated code
    ...
}

UI

4

0 に答える 0