help with a Car Dealer program


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: help with a Car Dealer program

  1. #1
    Join Date
    Jun 2006
    Posts
    1

    help with a Car Dealer program

    hi, i'm writing a Car Dealer program for school that is supposed to allow a user to browse and (if they want) purchase a car.
    right now i've got this glitchy thing (i think it's a glitch :/) in one of my JComboBoxes
    in my program there are 2 combo boxes, the first one allows the user to select a method to browse by. then for some items which would have subitems (such as if they choose to browse by Car Type, then the subitems would list various car types to browse), these subitems would then be set in the second combo box. the weird thing happening is that for i don't know what reason, the subitems in the second combo box are set twice :/
    can anyone help me figure out why this is happening?^^;

    here's the source code for the Frame class where the Combo boxes are used:
    Code:
    import java.awt.*;
    import java.awt.Dimension;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class DealerFrame extends JFrame
    {
        public DealerFrame()
        {
            NewCars ncar1 = new NewCars("BMW", "Family Car", "New", "Z3", 35000);
            NewCars ncar2 = new NewCars("Mercedes", "SUV", "New", "LE", 35000);
            OldCars ocar1 = new OldCars("Volvo", "Family Car", "Old", "Z3", 35000);
            OldCars ocar2 = new OldCars("Toyota", "Family Car", "Old", "Camry", 20000);
            Object[] ncarArray = {ncar1, ncar2, ocar1, ocar2};
            Dealer carDealer = new Dealer();
            carDealer.addCar(new NewCars("BMW", "Family Car", "New", "Z3", 35000));
            carDealer.addCar(new OldCars("Toyota", "Family Car", "New", "Camry", 20000));
            
            final JTextArea browsearea = new JTextArea("Welcome to __ Car Dealer we currently have: " + carDealer.getTotal() + " cars in stock.\n", 20, 10);
            getContentPane().add(browsearea, BorderLayout.CENTER);
            getContentPane().add(createDealerPanel(), BorderLayout.NORTH);
            getContentPane().add(createPurchasePanel(), BorderLayout.SOUTH);
            pack();
            show();
        }
        
        public JPanel createDealerPanel()
        {
            JLabel browselabel = new JLabel("Select a method to browse by:");
            browsecombo = new JComboBox();
            browsecombo.addItem("Car Type");
            browsecombo.addItem("Manufacturer");
            browsecombo.addItem("New Cars");
            browsecombo.addItem("Used Cars");
            
            JLabel carsets = new JLabel("Select the Type/Manufacturer you want to browse:\n");
            selectcars = new JComboBox();
    
            class startCheck implements ActionListener
            {  
                public void actionPerformed(ActionEvent event)
                {
                    selectcars.removeAllItems();
                    if((String)browsecombo.getSelectedItem() == "Car Type")
                    {
                        selectcars.addItem("Family Cars");
                        selectcars.addItem("Minivans");
                        selectcars.addItem("Vans");
                        selectcars.addItem("SUV");
                    }
                    if((String)browsecombo.getSelectedItem() == "Manufacturer")
                    {
                        selectcars.addItem("BMW");
                        selectcars.addItem("Toyota");
                        selectcars.addItem("GM");
                        selectcars.addItem("Mercedes");
                    }
                    if((String)browsecombo.getSelectedItem() == "New Cars")
                    {
                        browsearea.append(Object[0] + "\n" + Object[1]);
                    }
                    if((String)browsecombo.getSelectedItem() == "Old Cars")
                    {
                    }
                }
            }
            startCheck listener = new startCheck();
            browsecombo.addActionListener(listener);
            
            class searchCar implements ActionListener
            {
                public void actionPerformed(ActionEvent event)
                {
                   
                    
                }
            }
            searchCar listener2 = new searchCar();
            selectcars.addActionListener(listener2);
            
            JPanel browsePanel1 = new JPanel();
            browsePanel1.add(browselabel);
            browsePanel1.add(browsecombo);
            browsePanel1.add(carsets);
            browsePanel1.add(selectcars);
            return browsePanel1;
    
        }
        
        public JPanel createPurchasePanel()
        {
            JLabel purchaseLabel = new JLabel("Purchase a Car:\n");
            JLabel inmanufacLabel = new JLabel("Brand:");
            final JTextField inmanufac = new JTextField(5);
            
            JLabel intypeLabel = new JLabel("Type:");
            final JTextField intype = new JTextField(5);
            
            newButton = new JRadioButton("New");
            newButton.setSelected(true);
            oldButton = new JRadioButton("Old");
            
            ButtonGroup group = new ButtonGroup();
            group.add(newButton);
            group.add(oldButton);
            
            JLabel incolourLabel = new JLabel("Colour:");
            final JTextField incolour = new JTextField(5);
            
            JLabel inpriceLabel = new JLabel("Price:");
            final JTextField inprice = new JTextField(5);
            
            JButton purchaseButton = new JButton("Purchase Car");
            
            class purchaseListener implements ActionListener
            {   
                public void actionPerformed(ActionEvent event)
                {
                    //String repurchase = "";
                    if(newButton.isSelected())
                    {
                        String repurchase = "\nYou just purchased a " + "new " + incolour.getText() + " " + inmanufac.getText() + " " + intype.getText() + " for $" + inprice.getText();
                        browsearea.append(repurchase);
                    }
                    if(oldButton.isSelected())
                    {
                        String repurchase = "\nYou just purchased a " + "used " + incolour.getText() + " " + inmanufac.getText() + " " + intype.getText() + " for $" + inprice.getText();
                        browsearea.append(repurchase);
                    } 
                }
            }
            purchaseListener plistener = new purchaseListener();
            purchaseButton.addActionListener(plistener);        
            newButton.addActionListener(plistener);
            oldButton.addActionListener(plistener); 
            
            JPanel browsePanel2 = new JPanel();
            browsePanel2.add(purchaseLabel);
            browsePanel2.add(inmanufacLabel);
            browsePanel2.add(inmanufac);
            browsePanel2.add(intypeLabel);
            browsePanel2.add(intype);
            browsePanel2.add(newButton);
            browsePanel2.add(oldButton);
            browsePanel2.add(incolourLabel);
            browsePanel2.add(incolour);
            browsePanel2.add(inpriceLabel);
            browsePanel2.add(inprice);
            browsePanel2.add(purchaseButton);
            
            return browsePanel2;
        } 
        private JTextArea browsearea;
        private JComboBox browsecombo;
        private JComboBox selectcars;
        private JRadioButton newButton;
        private JRadioButton oldButton;
        private Dealer carDealer;
    }
    sorry if i sound kinda confusing ehehe..if you need any other parts of the program just ask and i will supply (there are about 7 classes and 1 interface)

  2. #2
    Join Date
    May 2008
    Posts
    1

    Hi

    Hi, my name is Nelly .I hava seen the part of your Car Dealer program .
    If it is not difficult for you , can you send me the other part on my mail Removed By Mod ? I mean other 7 classes and 1 interface.I will wait for your answear.
    Best regards Nelly Ter_Vardanyan
    Last edited by Hack; 05-07-2008 at 01:10 PM. Reason: Removed EMail Address

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    I have edited your post and removed your email address.

    You should never post your email address in an open post on an open forum. Mail spam bots can pick that up and before you know it, your mailbox is full of junk mail. If you wish to share your email address with other forum members, please do so via our PM system.

    In addition, we prefer all answers to questions be publically posted rather than sent via EMail or PM. That way, everyone with a similar problem can benefit.

    Thanks.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  4. #4
    Join Date
    May 2007
    Posts
    843
    You can send through PM.

Similar Threads

  1. soft drink Vending machine program
    By divagoddess in forum C++
    Replies: 5
    Last Post: 08-14-2009, 03:12 PM
  2. Prime number program to make go faster
    By divagoddess in forum C++
    Replies: 12
    Last Post: 05-07-2006, 10:55 PM
  3. problem in program in c++
    By mheasen in forum Architecture and Design
    Replies: 0
    Last Post: 03-20-2002, 09:24 AM
  4. Please help with running executable vb program.
    By Gordon Reichhardt in forum VB Classic
    Replies: 2
    Last Post: 01-08-2002, 10:06 AM
  5. How can I build copy protection into my program
    By W.Pierce in forum VB Classic
    Replies: 1
    Last Post: 12-11-2001, 08:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center