Reputation: 103
I have created a JRadioButton Group, and I want to set a parameter to a value when a specific button is selected. I have added ActionListener to this button like the codes. But I how can I use the value in other actionlisteners?
grid_rb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
network_type = "--grid-net";
}
});
Upvotes: 0
Views: 3666
Reputation: 4380
Buttons have a method isSelected()
, that tells you if the button is selected or not.
Upvotes: 1
Reputation: 59273
Use a getter and setter:
String networkType;
grid_rb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
setNetworkType("--grid-net");
}
});
public void getNetworkType() {
return networkType;
}
public void setNetworkType(String nwt) {
networkType = nwt;
}
Upvotes: 1