プロパティ ファイルで定義されている URL の数に基づいて動的に作成しようとしてJButton
います。JLabel
私がこれまでに試したことは次のとおりです。
AppResources.properties file
urls=http://google.com,http://stackoverflow.com,http://gmail.com
urlLabels=Internet Users,MPLS Users,Physical Access (Not Advised)
私のJavaプログラムでは、プロパティファイルを読んでいてcomma separator
、文字列の分割に基づいており、それに応じてボタンとラベルを生成する必要があります. などのようfirst URL Label --> first URL as Button
に。
これまでに行った方法は次のとおりです。
String url = properties.getProperty("urls");
String urlLabel = properties.getProperty("urlLabels");
String[] jButton = url.split(",");
String[] jLabel = urlLabel.split(",");
for (int i = 0; i < jLabel.length; i++) {
JLabel labels = new JLabel(jLabel[i]);
panel.add(labels);
for (int j = 0; j < jButton.length; j++) {
JButton button = new JButton(jButton[j]);
panel.add(button);
}
}
ただし、ラベルのボタンを 3 回印刷します。これを修正する方法は?また、これらのボタンのアクション リスナーを作成する方法は?