私がやろうとした以下のコードがありますが、最後のGridLayout
(インテリジェンス統計)に(マイナス/プラスボタン)しか表示されません:
JButton plusButton = new JButton("+");
JButton minusButton = new JButton("-");
statStrengthGridPanel = new JPanel(new GridLayout(1,3));
statStrengthGridPanel.add(minusButton);
statStrengthGridPanel.add(new JLabel("10"));
statStrengthGridPanel.add(plusButton);
statConstitutionGridPanel = new JPanel(new GridLayout(1,3));
statConstitutionGridPanel.add(minusButton);
statConstitutionGridPanel.add(new JLabel("10"));
statConstitutionGridPanel.add(plusButton);
statDexterityGridPanel = new JPanel(new GridLayout(1,3));
statDexterityGridPanel.add(minusButton);
statDexterityGridPanel.add(new JLabel("10"));
statDexterityGridPanel.add(plusButton);
statIntelligenceGridPanel = new JPanel(new GridLayout(1,3));
statIntelligenceGridPanel.add(minusButton);
statIntelligenceGridPanel.add(new JLabel("10"));
statIntelligenceGridPanel.add(plusButton);
パネル名(複数の名前があります)に対して行ったようなことができることは知っていますが、そもそもパネルに対してはそれを行いたくありません。私はベストプラクティスを使用しようとしていますが、コードを繰り返したくありません。助言がありますか??
目標は、デクリメントボタンとインクリメントボタンを使用して、ポイントを割り当てるための4つの統計情報を用意することです(スライダーを使用しないことにしました)。最終的には、上限と下限があり、「未使用」のラベルとそのすべての優れたものが減りますが、繰り返したくないだけです。