GUIビルダーを使用して、JFrame
を含むシンプルなものを作成していますJPanel
. 乱数のJButton
s をパネルに追加したいのですが、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
...
}