Hello,
I have a user interface using swing. I have 3 radio buttons grouped (Economy, Business, First). I want to find which one the user has clicked. I have grouped the radio buttons and placed them inside a panel. I have added addItemListener to each one. I have used to the code below to print out the radio button that have been clicked. I want to print out either Economy, Business or First, depending on which one the user clicked.
All this code does is print out a load of rubbish, each time a radio button is clicked. Not sure why.
public void itemStateChanged(ItemEvent event)
{
String item = "";
if ( event.getStateChange() == ItemEvent.SELECTED )
{
item = event.getItem().toString();
System.out.println("Radio Button: " + item);
}
}
Thanks in advance,
Steve
I have a user interface using swing. I have 3 radio buttons grouped (Economy, Business, First). I want to find which one the user has clicked. I have grouped the radio buttons and placed them inside a panel. I have added addItemListener to each one. I have used to the code below to print out the radio button that have been clicked. I want to print out either Economy, Business or First, depending on which one the user clicked.
All this code does is print out a load of rubbish, each time a radio button is clicked. Not sure why.
public void itemStateChanged(ItemEvent event)
{
String item = "";
if ( event.getStateChange() == ItemEvent.SELECTED )
{
item = event.getItem().toString();
System.out.println("Radio Button: " + item);
}
}
Thanks in advance,
Steve