Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package finalExam;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- //import java.util.*;
- import java.text.NumberFormat;
- public class vacationPanel extends JPanel {
- private JLabel hotelL, locationL, rentalL, nightsL, airlineL;
- private JTextField Nights, calcResults;
- private JButton vacationCalc;
- private JRadioButton rentalYes, rentalNo, delta, unitedAirlines, jetBlue, bestWestern, lastResort, marriott, hawaii, tokyoJapan, perthAustralia;
- private double hotelPick, locationPick, airlinePick, nightsPick, carRentalPick, finalPrice;
- vacationPanel()
- {
- hotelL = new JLabel ("Choose Hotel");
- locationL = new JLabel ("Choose Location");
- rentalL = new JLabel ("Car Rental?");
- nightsL = new JLabel ("How many nights?");
- airlineL = new JLabel ("Choose Airline");
- Nights = new JTextField ( 5 );
- vacationCalc = new JButton ( "Get Price!");
- rentalYes = new JRadioButton ("yes");
- rentalNo = new JRadioButton ("no");
- delta = new JRadioButton ("Delta");
- unitedAirlines = new JRadioButton ("United Airlines");
- jetBlue = new JRadioButton ("JetBlue");
- ButtonGroup rentalGroup = new ButtonGroup();
- rentalGroup.add(rentalYes);
- rentalGroup.add(rentalNo);
- ButtonGroup airlineGroup = new ButtonGroup();
- airlineGroup.add(delta);
- airlineGroup.add(unitedAirlines);
- airlineGroup.add(jetBlue);
- ButtonGroup hotelGroup = new ButtonGroup();
- hotelGroup.add(bestWestern);
- hotelGroup.add(lastResort);
- hotelGroup.add(marriott);
- ButtonGroup locationGroup = new ButtonGroup();
- locationGroup.add(hawaii);
- locationGroup.add(tokyoJapan);
- locationGroup.add(perthAustralia);
- vacationCalc.addActionListener(new calcListener() );
- //calcResults.addActionListener(new calcListener() );
- rentalYes.addActionListener(new rentalListener() );
- rentalNo.addActionListener(new rentalListener() );
- delta.addActionListener(new airlineListener() );
- unitedAirlines.addActionListener(new airlineListener() );
- jetBlue.addActionListener(new airlineListener() );
- bestWestern.addActionListener(new hotelListener() );
- lastResort.addActionListener(new hotelListener() );
- marriott.addActionListener(new hotelListener() );
- hawaii.addActionListener(new locationListener() );
- tokyoJapan.addActionListener(new locationListener() );
- perthAustralia.addActionListener(new locationListener() );
- add (hotelL);
- add (bestWestern);
- add (lastResort);
- add (marriott);
- add (locationL);
- add (hawaii);
- add (tokyoJapan);
- add (perthAustralia);
- add (rentalL);
- add (rentalYes);
- add (rentalNo);
- add (nightsL);
- add (Nights);
- add (airlineL);
- add (delta);
- add (unitedAirlines);
- add (jetBlue);
- add (vacationCalc);
- add (calcResults);
- setPreferredSize (new Dimension(512,288) );
- setBackground (Color.blue );
- }
- private class calcListener implements ActionListener {
- public void actionPerformed (ActionEvent event) {
- String nightsText = Nights.getText();
- nightsPick = Double.parseDouble(nightsText);
- finalPrice = ((hotelPick * nightsPick * 250.00) + (locationPick * airlinePick * 1000.00) + (carRentalPick * nightsPick));
- NumberFormat fmt = NumberFormat.getNumberInstance();
- calcResults.setText(fmt.format(finalPrice) );
- }
- }
- private class rentalListener implements ActionListener {
- public void actionPerformed (ActionEvent choose) {
- if (choose.getSource() == rentalYes)
- carRentalPick = 50.00;
- else if (choose.getSource() == rentalNo)
- carRentalPick = 00.00;
- }
- }
- private class hotelListener implements ActionListener {
- public void actionPerformed (ActionEvent choose) {
- if (choose.getSource() == bestWestern)
- hotelPick = 01.00;
- else if (choose.getSource() == lastResort)
- hotelPick = 00.65;
- else if (choose.getSource() == marriott)
- hotelPick = 01.85;
- }
- }
- private class locationListener implements ActionListener {
- public void actionPerformed (ActionEvent choose) {
- if (choose.getSource() == hawaii)
- locationPick = 01.00;
- else if (choose.getSource() == tokyoJapan)
- locationPick = 02.85;
- else if (choose.getSource() == perthAustralia)
- locationPick = 01.95;
- }
- }
- private class airlineListener implements ActionListener {
- public void actionPerformed (ActionEvent choose) {
- if (choose.getSource() == delta)
- airlinePick = 01.00;
- else if (choose.getSource() == unitedAirlines)
- airlinePick = 00.85;
- else if (choose.getSource() == jetBlue)
- airlinePick = 01.40;
- }
- }
- //this is to fix a warning message "The serializable class does not declare a static final SerialVersionUID field of type long"
- JTextArea error_fix = new JTextArea(5, 100);
- private static final long serialVersionUID = 1L;
- }
- vacationDemo.main(vacationDemo.java:11)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement