这是代码:
String male = "Male";
String female = "Female";
JRadioButton checkGenderMale = new JRadioButton(male);
checkGenderMale.addActionListener(new genderListener());
JRadioButton checkGenderFemale = new JRadioButton(female);
checkGenderMale.addActionListener(new genderListener());
class genderListener implements ActionListener{
public void actionPerformed(ActionEvent event){
System.out.println( );
}
}
在System.out.println()行中;我想要打印选项(选择的字符串男性或女性)。那么括号中可能会出现什么?
答案 0 :(得分:3)
你需要写
AbstractButton aButton = (AbstractButton) actionEvent.getSource();
System.out.println("Selected: " + aButton.getText());
在你的行动方法中。