Click here to Skip to main content
15,887,746 members
Home / Discussions / Java
   

Java

 
GeneralRe: Java Bubble Sort Pin
Richard MacCutchan7-Aug-15 21:09
mveRichard MacCutchan7-Aug-15 21:09 
GeneralRe: Java Bubble Sort Pin
Frankie12459-Aug-15 9:33
Frankie12459-Aug-15 9:33 
GeneralRe: Java Bubble Sort Pin
Richard MacCutchan10-Aug-15 0:54
mveRichard MacCutchan10-Aug-15 0:54 
GeneralRe: Java Bubble Sort Pin
Frankie124510-Aug-15 3:22
Frankie124510-Aug-15 3:22 
GeneralRe: Java Bubble Sort Pin
Richard MacCutchan10-Aug-15 3:34
mveRichard MacCutchan10-Aug-15 3:34 
Questioncennect unicenta with a phone problem Pin
Member 116403425-Aug-15 4:56
Member 116403425-Aug-15 4:56 
AnswerRe: cennect unicenta with a phone Pin
Richard MacCutchan5-Aug-15 5:23
mveRichard MacCutchan5-Aug-15 5:23 
QuestionJava Application Help - Inner Class? Pin
Member 1072866731-Jul-15 21:43
Member 1072866731-Jul-15 21:43 
My program this week is to create an application that will calculate services (oil change, car wash, or both) provided to customers. The services should be totaled and a message box should display the services rendered and the total sales amount for the purchase. Also, the client should be able to clear the application for a new user. For whatever reason, this inner class is confusing me, and I'm not sure that I'm even on the right track. Any help would be greatly appreciated.
Java

C#
import javax.swing.JFrame;

public class CarCareTest {

    public static void main(String[] args) {

        CarCare myCarCare = new CarCare();
        myCarCare.setSize(500, 500);
        myCarCare.setVisible(true);
        myCarCare.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

}

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;

public class CarCare extends JFrame {

    //Declare Class Variables
    private JMenuItem bronzeOil, silverOil, goldOil;
    private JMenuItem basicWash, betterWash, bestWash;
    private JMenuItem total, clear, exit;
    private int priceOilChange, priceCarWash;

    //Create Constructor
    public CarCare(){
        super("Quick Fast Car Care");

        //Instantiate Top Level Menu Items
        JMenu oilchangeMenu = new JMenu ("Oil Change");
        JMenu carwashMenu = new JMenu ("Car Wash");
        JMenu totalclearexitMenu = new  JMenu ("Total/Clear/Exit");

        //Instantiate Sub Menu Items
        bronzeOil = new JMenuItem("Bronze");
        silverOil = new JMenuItem("Silver");
        goldOil = new JMenuItem("Gold");
        basicWash = new JMenuItem("Basic");
        betterWash = new JMenuItem("Better");
        bestWash = new JMenuItem("Best");
        total = new JMenuItem("Total");
        clear = new JMenuItem("Clear");
        exit = new JMenuItem("Exit");

        //Set Layout Manager
        setLayout(new FlowLayout());

        //Add Sub Menu Items To Top Level Menu
        oilchangeMenu.add(bronzeOil);
        oilchangeMenu.add(silverOil);
        oilchangeMenu.add(goldOil);
        carwashMenu.add(basicWash);
        carwashMenu.add(betterWash);
        carwashMenu.add(bestWash);
        totalclearexitMenu.add(total);
        totalclearexitMenu.add(clear);
        totalclearexitMenu.add(exit);

        //Create Menu Bar
        JMenuBar bar = new JMenuBar();

        //Add Top Level(s) To Menu Bar
        bar.add(oilchangeMenu);
        bar.add(carwashMenu);
        bar.add(totalclearexitMenu);

        //Add Menu Bar To JFrame 
        setJMenuBar(bar);

        //Create MenuHandlerObject
        MenuHandler handler = new MenuHandler();

        //Add Event Handling Listeners
        bronzeOil.addActionListener(handler);
        silverOil.addActionListener(handler);
        goldOil.addActionListener(handler);
        basicWash.addActionListener(handler);
        betterWash.addActionListener(handler);
        bestWash.addActionListener(handler);
        total.addActionListener(handler);
        clear.addActionListener(handler);
        exit.addActionListener(handler);
    }//End Constructor

        //Display Output

    //Create Inner Class
    private class MenuHandler implements ActionListener{
        public void actionPerformed(ActionEvent event) {
            System.out.println("MenuHandler Called.");

            //Determine Oil Change & Set Price 
            if (event.getSource() == bronzeOil){
                priceOilChange = 20;}
            else if (event.getSource() == silverOil);{
                priceOilChange = 25;}
            if (event.getSource() == goldOil){
                priceOilChange = 30;}

            //Determine Car Wash & Set Price
            if (event.getSource() == basicWash) {
                priceCarWash = 5;}
            else if (event.getSource() == betterWash);{
                priceCarWash = 10;}
            if (event.getSource() == bestWash){
                priceCarWash = 15;}

            //Determine Total
            if (event.getSource() == total){
            }

            //Clear Application
            if (event.getSource() == clear){
            }

            //Exit Application
            if (event.getSource() == exit){
            System.exit(0);}

        }//End ActionPerformed Method
    }//End MenuHandler Class
}//End CarCare Class

AnswerRe: Java Application Help - Inner Class? Pin
Afzaal Ahmad Zeeshan2-Aug-15 1:55
professionalAfzaal Ahmad Zeeshan2-Aug-15 1:55 
QuestionJAVA SERVLETS and PHP Pin
anaQata31-Jul-15 5:10
professionalanaQata31-Jul-15 5:10 
AnswerRe: JAVA SERVLETS and PHP Pin
Richard MacCutchan1-Aug-15 22:10
mveRichard MacCutchan1-Aug-15 22:10 
GeneralRe: JAVA SERVLETS and PHP Pin
anaQata1-Aug-15 23:21
professionalanaQata1-Aug-15 23:21 
GeneralRe: JAVA SERVLETS and PHP Pin
Richard MacCutchan2-Aug-15 1:12
mveRichard MacCutchan2-Aug-15 1:12 
AnswerRe: JAVA SERVLETS and PHP Pin
Member 119648056-Sep-15 22:58
Member 119648056-Sep-15 22:58 
QuestionJava Pin
jubayer30-Jul-15 0:29
jubayer30-Jul-15 0:29 
AnswerRe: Java Pin
Pete O'Hanlon30-Jul-15 0:45
mvePete O'Hanlon30-Jul-15 0:45 
QuestionJava Set Game Pin
Member 1186286325-Jul-15 6:58
Member 1186286325-Jul-15 6:58 
AnswerRe: Java Set Game Pin
Richard MacCutchan25-Jul-15 8:17
mveRichard MacCutchan25-Jul-15 8:17 
QuestionJava Applet Help Pin
Member 1072866723-Jul-15 0:38
Member 1072866723-Jul-15 0:38 
AnswerRe: Java Applet Help Pin
Richard MacCutchan23-Jul-15 21:12
mveRichard MacCutchan23-Jul-15 21:12 
GeneralRe: Java Applet Help Pin
anaQata31-Jul-15 4:58
professionalanaQata31-Jul-15 4:58 
GeneralRe: Java Applet Help Pin
Richard MacCutchan31-Jul-15 5:04
mveRichard MacCutchan31-Jul-15 5:04 
QuestionCode Help! Pin
Member 1072866719-Jul-15 7:58
Member 1072866719-Jul-15 7:58 
AnswerRe: Code Help! Pin
Wendelius19-Jul-15 9:13
mentorWendelius19-Jul-15 9:13 
GeneralRe: Code Help! Pin
Member 1072866719-Jul-15 9:29
Member 1072866719-Jul-15 9:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.