私のアプリケーションではJRadioButton
、「選択」にグループ化された2つを作成しましたButtonGroup
。ActionListener
「SelectionListener」という名前を追加しました。RadioButton
を使用して自分が選択されているかどうかを確認isSelected()
すると、選択がに渡されていないようActionListener
です。
public static void main(String[] args) {
JRadioButton monthlyRadioButton = new JRadioButton("Monthly Payment", true);
JRadioButton loanAmountButton = new JRadioButton("Loan Amount");
ButtonGroup selection = new ButtonGroup();
selection.add(monthlyRadioButton);
selection.add(loanAmountButton);
monthlyRadioButton.addActionListener(new SelectionListener());
loanAmountButton.addActionListener(new SelectionListener());
}
SelectionListener.java
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class SelectionListener implements ActionListener {
public void actionPerformed(ActionEvent event){
if(event.getSource() == monthlyRadioButton)
System.out.println("You clicked Monthly");
else
System.out.println("You clicked Loan Amount");
}
}
パラメータがクラスmonthlyRadioButton
に渡されていません。SelectionListener
解決されていないというエラーが表示されます。
monthlyRadioButton
mainメソッドのをSelectionListener
クラスに渡すにはどうすればよいですか?