This is what I am trying to accomplish: Write an application for Lambert’s Vacation Rentals. Use separate ButtonGroups to allow a client to select one of three locations, the number of bedrooms, and whether meals are included in the rental. Assume that the locations are parkside for $600 per week, poolside for $750 per week, or lakeside for $825 per week. Assume that the rentals have one, two or three bedrooms and that each bedroom over one adds %75 to the base prices. Assume that if meals are added, the price is $200 more per rental.
And so far this is what I have but I can't for the life of me, figure out where i am going wrong with the actionlistener stuff. I have tried a dozen different ways to do this. I just need a pointer in the correct direction to get this code moving again.
package swing; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Swing extends JFrame implements ActionListener { public static void main(String[] args) { final int parkside = 600, poolside = 750, lakeside = 825; final int plusmeals = 200, onebed = 0, twobed = 75, threebed = 150; int total; JFrame frame = new JFrame ("Lamberts Vacation Rentals"); frame.setVisible (true); frame.setSize(400,400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); frame.add(panel); JLabel vacation = new JLabel("Lamberts Vacation Rental"); JLabel price = new JLabel("The price for your vacation is: "); JRadioButton loc1, loc2, loc3, room1, room2, room3; JCheckBox meals, none; JTextField finaltotal = new JTextField(8); loc1 = new JRadioButton("Parkside $600"); loc2 = new JRadioButton("Poolside $750"); loc3 = new JRadioButton("Lakeside $825"); meals = new JCheckBox ("Include meals for $200"); none = new JCheckBox ("Do NOT include meals"); room1 = new JRadioButton("One Bedroom"); room2 = new JRadioButton("Two bedrooms (add $75)"); room3 = new JRadioButton("Three bedrooms (add $150)"); ButtonGroup location = new ButtonGroup(); location.add(loc1); location.add(loc2); location.add(loc3); panel.add(vacation); panel.add(loc1); panel.add(loc2); panel.add(loc3); ButtonGroup addmeals = new ButtonGroup(); addmeals.add(meals); addmeals.add(none); panel.add(meals); panel.add(none); ButtonGroup bedrooms = new ButtonGroup(); bedrooms.add(room1); bedrooms.add(room2); bedrooms.add(room3); panel.add(room1); panel.add(room2); panel.add(room3); panel.add(price); panel.add(finaltotal); finaltotal.setText("$" + finaltotal); public Swing (); loc1.addActionListener(new Action()); loc2.addActionListener(new Action()); loc3.addActionListener(new Action()); meals.addActionListener(new Action()); none.addActionListener(new Action()); room1.addActionListener(new Action()); room2.addActionListener(new Action()); room3.addActionListener(new Action()); } public void actionPerformed (ActionEvent e) { Object source = e.getSource(); if(source == JRadioButton){ if (select == e.SELECTED); } }