public class RoomListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
double roomtype;
if (event.getSource() == room1)
roomtype = 60;
else if (event.getSource() == room2)
roomtype = 75;
else
roomtype = 100;
}
}
public class CostListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
double NightLength, roomNumber, cost;
String NightText = NumberOfNights.getText();
String RoomText = NumberOfRooms.getText();
NightLength = Double.parseDouble(NightText);
roomNumber = Double.parseDouble(RoomText);
RoomListener.actionPerformed(RoomType);
cost = roomtype * NightLength * roomNumber;
CostCalculation.setText(Double.toString(cost));
NumberFormat fmt = NumberFormat.getNumberInstance();
CostCalculation.setText(fmt.format(cost));
}
}
I am trying to set a value to an already string labeled radio button. I do not understand my mistake

- 127,765
- 105
- 273
- 257

- 1
- 2
-
3so what's the problem? what error are you getting? – 0x6C38 Dec 06 '16 at 23:42
-
for RoomListener.actionPerformed(roomtype); - it says that "The method actionPerformed(ActionEvent) in the type HotelBookingPanel.RoomListener is not applicable for the arguments (double)" – Sam D. Dec 07 '16 at 01:07
1 Answers
RoomListener.actionPerformed(RoomType);
This isn't a
static
method. You can't call it using the class name.What is
RoomType
? If it isn't anActionEvent
, then it won't work. Look at the method.public void actionPerformed(ActionEvent event)
You really shouldn't be calling out to another listener's actionPerformed, or at least I can't think of a reason to. You need to add a
new RoomListener()
onto your RadioButtons. Though, I'd suggest you look into a RadioGroup class, and reading the JavaDoc for the correct listener which lets you determine the source of the selected radio button.Nothing is returned from this method.
double roomtype
is a local variable and it is discarded (garbage collected) when you exit this method. Maybe you meant to modify a member variable?this.roomtype
? Along with that point - I can't tell whatroom1
androom2
are here... They don't seem to be accessible.public void actionPerformed(ActionEvent event) { double roomtype; if (event.getSource() == room1) roomtype = 60; else if (event.getSource() == room2) roomtype = 75; else roomtype = 100; }

- 179,855
- 19
- 132
- 245