ボタンにカウンタを追加したい設定したカウント数に達すると、コンピュータ上のファイルを開くように各カウンタを設定する方法も学びたいGUIにカウンタを追加する方法
package layout;
import java.awt.Component;
import java.awt.Container;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class BoxLayoutDemo {
public static void addComponentsToPane(Container pane) {
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
addAButton("Section 1", pane);
addAButton("Section 2", pane);
addAButton("Section 3", pane);
addAButton("Section 4", pane);
addAButton("Section 5", pane);
addAButton("Section 6", pane);
addAButton("Section 7", pane);
addAButton("Section 8", pane);
addAButton("Section 9", pane);
}
private static void addAButton(String text, Container container) {
JButton button = new JButton(text);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
container.add(button);
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("Counter");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addComponentsToPane(frame.getContentPane());
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
`
私がnoobですので、これを行う方法を見つけるのに数週間かかりました。
あなたのコードで
ようこそ。あなたの具体的な質問は何ですか? * "それは私が設定したカウント数に達すると.." *何?返信する精神的な人々とのフォーラムを見つけるまでは、できるだけ友だちにあなたの投稿を注意深く読んで、投稿する前にそれが意味をなさないことを確認することをお勧めします。 –
BTW 'addAButton("セクション1 "区画); .. addAButton( "Section 9"、pane); 'ループをマスターする前にGUIプログラミングを行うのは、奇妙なことです。それは土台や構造物がない家に排水溝を塗ってみるようなものです。 –
申し訳ありませんが、私はすべての準備ができている6つの.exeファイルの1つを開きますカウント番号に達すると意味します。 – user1359327