Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 20 of 20

Thread: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    I am not getting any compiling errors except warnings but the layout is working like it should. Using my text book I can create a JFrame with the panel and text boxes and I can create the JFrame with ComboBoxes it just doesn't tell me how to do them both at the same time. Any help would be appreciated. I don't want you to just give me the code which most here don't but if you have any suggested locations where this can be read so I can learn it that would be more helpful.

    /* Chapter 7
     * 
     *
    */
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
     
     
    public class TripCalc extends JFrame implements ActionListener
    {  
       //construct components
       JLabel fuelPrompt = new JLabel("Fuel Costs");
       JComboBox fuelCombo = new javax.swing.JComboBox();
       JTextPane fuelPane = new JTextPane();
     
       JLabel beginningPrompt = new JLabel("Starting Location");
       JComboBox startCombo = new javax.swing.JComboBox();
       JTextPane startPane = new JTextPane();
     
       JLabel endPrompt = new JLabel("Ending Location");
       JComboBox endCombo = new javax.swing.JComboBox();
       JTextPane endPane = new JTextPane();
     
           // Panel Creation
        JPanel firstRow = new JPanel();
        JPanel secondRow = new JPanel();
     
        // Panel for Fields and Buttons
        JPanel fieldPanel = new JPanel();
        JPanel buttonPanel = new JPanel();
     
        // Construct Labels and TextBoxes
        JLabel Miles = new JLabel("Miles planning to travel");
          JTextField distance = new JTextField(10);
        JLabel Fuelcost = new JLabel("What is the price per gallon/litre?");
          JTextField fuelprice = new JTextField(5);
        JButton submitButton = new JButton("Submit"); 
     
      //create the content pane
      public Container createContentPane()
      {
        //populate the JCombobox
        fuelCombo.addItem("Leaded");
        fuelCombo.addItem("Unleaded");
        fuelCombo.addItem("Super Unleaded");
        fuelCombo.addItem("Diesel");
        fuelCombo.addActionListener(this);
        fuelCombo.setToolTipText("Click on the type of fuel you will be using");
     
        startCombo.addItem("Minneapolis");
        startCombo.addItem("Duluth");
        startCombo.addItem("Bemidji");
        startCombo.addItem("Rochester");
        startCombo.addItem("Detroit Lakes");
        startCombo.addItem("St.Cloud");
        startCombo.addActionListener(this);
        startCombo.setToolTipText("Click on your starting City.");
     
        endCombo.addItem("Daytona");
        endCombo.addItem("Darlington");
        endCombo.addItem("Las Vegas");
        endCombo.addItem("Talladega");
        endCombo.addItem("Richmond");
        endCombo.addItem("Chicago");
        endCombo.addActionListener(this);
        endCombo.setToolTipText("Click on your starting City.");
     
        //construct and populate the north panel
        JPanel northPanel = new JPanel();
        northPanel.setLayout(new FlowLayout());
        northPanel.add(fuelPrompt);
        northPanel.add(fuelCombo);
        northPanel.add(beginningPrompt);
        northPanel.add(startCombo);
        northPanel.add(endPrompt);
        northPanel.add(endCombo);
     
     
     
     
     
         //createContainer and set attributes
         Container f = getContentPane();
         setLayout(new BorderLayout(20,20));
         fieldPanel.setLayout(new GridLayout(4,2));
         FlowLayout rowSetup = new FlowLayout(FlowLayout.LEFT,4,2);
             firstRow.setLayout(rowSetup);
             secondRow.setLayout(rowSetup);
         buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));    
         add(northPanel,BorderLayout.NORTH);
         setLocation(200,200);
         return f;
         }
         //main method executes at run time
         public static void main(String args[])
         {
           TripCalc f = new TripCalc();
           f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           f.setContentPane(f.createContentPane());
           f.setTitle("Trip Calculator"); 
           f.setSize(800,300);
           f.setVisible(true);
         }  
     
     
         // event to process user clicks
         public void actionPerformed(ActionEvent e)
         {
           String arg = e.getActionCommand();
         }
     
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    how to do them both at the same time
    Can you explain what your problem is?
    Are you trying to build a GUI displaying multiple components like textboxes and comboboxes?

    First you need to have a design of where they all go.
    Then use JPanels to hold different combinations of the components and add those JPanels to the JfFrame where you want them shown.
    See the tutorial: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    I've gotten to the text fields are there but no button or anything else.
    /* Chapter 7
     * 
     *
    */
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
     
     
    public class TripCalc extends JFrame implements ActionListener
    {  
       //construct components
       JLabel fuelPrompt = new JLabel("Fuel Costs");
       JComboBox fuelCombo = new javax.swing.JComboBox();
       JTextPane fuelPane = new JTextPane();
     
       JLabel beginningPrompt = new JLabel("Starting Location");
       JComboBox startCombo = new javax.swing.JComboBox();
       JTextPane startPane = new JTextPane();
     
       JLabel endPrompt = new JLabel("Ending Location");
       JComboBox endCombo = new javax.swing.JComboBox();
       JTextPane endPane = new JTextPane();
     
           // Panel Creation
        JPanel firstRow = new JPanel();
        JPanel secondRow = new JPanel();
     
        // Panel for Fields and Buttons
        JPanel fieldPanel = new JPanel();
        JPanel buttonPanel = new JPanel();
     
        // Construct Labels and TextBoxes
        JLabel Miles = new JLabel("Miles planning to travel");
          JTextField distance = new JTextField(10);
        JLabel Fuelcost = new JLabel("What is the price per gallon/litre?");
          JTextField fuelprice = new JTextField(5);
        JButton submitButton = new JButton("Submit"); 
     
      //create the content pane
      public Container createContentPane()
      {
        //populate the JCombobox
        fuelCombo.addItem("Leaded");
        fuelCombo.addItem("Unleaded");
        fuelCombo.addItem("Super Unleaded");
        fuelCombo.addItem("Diesel");
        fuelCombo.addActionListener(this);
        fuelCombo.setToolTipText("Click on the type of fuel you will be using");
     
        startCombo.addItem("Minneapolis");
        startCombo.addItem("Duluth");
        startCombo.addItem("Bemidji");
        startCombo.addItem("Rochester");
        startCombo.addItem("Detroit Lakes");
        startCombo.addItem("St.Cloud");
        startCombo.addActionListener(this);
        startCombo.setToolTipText("Click on your starting City.");
     
        endCombo.addItem("Daytona");
        endCombo.addItem("Darlington");
        endCombo.addItem("Las Vegas");
        endCombo.addItem("Talladega");
        endCombo.addItem("Richmond");
        endCombo.addItem("Chicago");
        endCombo.addActionListener(this);
        endCombo.setToolTipText("Click on your starting City.");
     
        //construct and populate the north panel
        JPanel northPanel = new JPanel();
        northPanel.setLayout(new FlowLayout());
        northPanel.add(fuelPrompt);
        northPanel.add(fuelCombo);
        northPanel.add(beginningPrompt);
        northPanel.add(startCombo);
        northPanel.add(endPrompt);
        northPanel.add(endCombo);
     
        JPanel southPanel = new JPanel();
        southPanel.setLayout(new FlowLayout());
        southPanel.add(distance);
        southPanel.add(fuelprice);
     
     
     
     
     
         //createContainer and set attributes
         Container f = getContentPane();
         setLayout(new BorderLayout(40,40));
         fieldPanel.setLayout(new GridLayout(2,1));
         FlowLayout rowSetup = new FlowLayout(FlowLayout.LEFT,2,1);
             firstRow.setLayout(rowSetup);
             secondRow.setLayout(rowSetup);
         buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));    
         add(northPanel,BorderLayout.NORTH);
         add(southPanel,BorderLayout.CENTER);
         setLocation(200,200);
         return f;
         }
         //main method executes at run time
         public static void main(String args[])
         {
           TripCalc f = new TripCalc();
           f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           f.setContentPane(f.createContentPane());
           f.setTitle("Trip Calculator"); 
           f.setSize(800,300);
           f.setVisible(true);
         }  
     
     
         // event to process user clicks
         public void actionPerformed(ActionEvent e)
         {
           String arg = e.getActionCommand();
         }
     
     
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    Where do you add any buttons to a container?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    I am trying to create an applet that will show drop down boxes that display fuel types (have that working) along with 6 cities to start from and destinations (got those also working). I am to have 2 text fields where I can input Miles and Cost per gallon along with a submit button and clear button. I've got the Submit Button and Clear button to display properly. I also have the text boxes, but I am working on getting the text labels to show up. My existing code below.

    /* Chapter 7
     * 
     *
    */
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
     
     
    public class TripCalc extends JFrame implements ActionListener
    {  
       //construct components
       JLabel fuelPrompt = new JLabel("Fuel Type");
       JComboBox fuelCombo = new javax.swing.JComboBox();
       JTextPane fuelPane = new JTextPane();
     
       JLabel beginningPrompt = new JLabel("Starting Location");
       JComboBox startCombo = new javax.swing.JComboBox();
       JTextPane startPane = new JTextPane();
     
       JLabel endPrompt = new JLabel("Ending Location");
       JComboBox endCombo = new javax.swing.JComboBox();
       JTextPane endPane = new JTextPane();
     
           // Panel Creation
        JPanel firstRow = new JPanel();
        JPanel secondRow = new JPanel();
     
        // Panel for Fields and Buttons
        JPanel fieldPanel = new JPanel();
        JPanel buttonPanel = new JPanel();
     
        // Construct Labels and TextBoxes
        JLabel Miles = new JLabel("Miles planning to travel");
          JTextField distance = new JTextField(10);
        JLabel Fuelcost = new JLabel("What is the price per gallon/litre?");
          JTextField fuelprice = new JTextField(5);
        JButton submitButton = new JButton("Submit"); 
        JButton clearButton = new JButton("Clear Fields");
     
      //create the content pane
      public Container createContentPane()
      {
        //populate the JCombobox
        fuelCombo.addItem("Leaded");
        fuelCombo.addItem("Unleaded");
        fuelCombo.addItem("Super Unleaded");
        fuelCombo.addItem("Diesel");
        fuelCombo.addActionListener(this);
     
        startCombo.addItem("Minneapolis");
        startCombo.addItem("Duluth");
        startCombo.addItem("Bemidji");
        startCombo.addItem("Rochester");
        startCombo.addItem("Detroit Lakes");
        startCombo.addItem("St.Cloud");
        startCombo.addActionListener(this);
     
        endCombo.addItem("Daytona");
        endCombo.addItem("Darlington");
        endCombo.addItem("Las Vegas");
        endCombo.addItem("Talladega");
        endCombo.addItem("Richmond");
        endCombo.addItem("Chicago");
        endCombo.addActionListener(this);
     
        //construct and populate the north panel
        JPanel northPanel = new JPanel();
        northPanel.setLayout(new FlowLayout());
        northPanel.add(fuelPrompt);
        northPanel.add(fuelCombo);
        northPanel.add(beginningPrompt);
        northPanel.add(startCombo);
        northPanel.add(endPrompt);
        northPanel.add(endCombo);
     
        JPanel southPanel = new JPanel();
        southPanel.setLayout(new FlowLayout());
        southPanel.add(distance);
        southPanel.add(fuelprice);
        firstRow.add(Miles);
        firstRow.add(Fuelcost);
        southPanel.add(submitButton);
        southPanel.add(clearButton);
     
     
     
     
     
     
         //createContainer and set attributes
         Container f = getContentPane();
         setLayout(new BorderLayout(40,40));
         fieldPanel.setLayout(new GridLayout(10,1));
         buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
         add(northPanel,BorderLayout.NORTH);
         add(southPanel,BorderLayout.SOUTH);
         setLocation(200,200);
         return f;
         }
         //main method executes at run time
         public static void main(String args[])
         {
           TripCalc f = new TripCalc();
           f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           f.setContentPane(f.createContentPane());
           f.setTitle("Trip Calculator"); 
           f.setSize(800,300);
           f.setVisible(true);
         }  
     
     
         // event to process user clicks
         public void actionPerformed(ActionEvent e)
         {
           String arg = e.getActionCommand();
         }
     
     
    }

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    I am trying to create an applet
    The posted code is an application not an applet. Applets execute in a browser.

    working on getting the text labels to show up
    Can you explain what the problem is when you execute the code? I see some labels when I compile and execute the code.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Nov 2012
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    If i'm understanding your question correctly i've added them to the center.Panel and south.Panel and then added those panels to the layout in the container.

    --- Update ---

    Quote Originally Posted by Norm View Post
    The posted code is an application not an applet. Applets execute in a browser.


    Can you explain what the problem is when you execute the code? I see some labels when I compile and execute the code.
    For the text boxes I want a label that says "How many miles do you plan to drive" and the other for "Fuel Price".

    I get labels for the ComboBoxes and the buttons, but not for my text boxes.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    I get labels for the ComboBoxes and the buttons, but not for my text boxes.
    What are the variable names for the labels that are not showing?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Nov 2012
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    I believe you are referring to JTextField distance and fuelprice?

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    I was asking for the names of the variables for the labels that are not showing so I can find them in the source and see where you haven't added them to the GUI that is being shown.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Nov 2012
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    JLabel Miles = new JLabel("Miles planning to travel");
          JTextField distance = new JTextField(10);
        JLabel Fuelcost = new JLabel("What is the price per gallon/litre?");
          JTextField fuelprice = new JTextField(5);
    I would like the labels to have those questions for the text and if I understand the variables are fuelprice and distance to later use in my calculation code.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    Where do you add those two JLabels to the GUI that is showing? Look at where you have added other components that are showing to see if you have added the missing labels in a way that they are added to the GUI that is showing. If they aren't connected to the GUI they won't show.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Nov 2012
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    Quote Originally Posted by JamesdTurnham View Post
    /* Chapter 7
     * 
     *
    */
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
     
     
    public class TripCalc extends JFrame implements ActionListener
    {  
     
     
     
       //construct components
       JLabel fuelPrompt = new JLabel("Fuel Type");
       JComboBox fuelCombo = new javax.swing.JComboBox();
       JTextPane fuelPane = new JTextPane();
     
       JLabel beginningPrompt = new JLabel("Starting Location");
       JComboBox startCombo = new javax.swing.JComboBox();
       JTextPane startPane = new JTextPane();
     
       JLabel endPrompt = new JLabel("Ending Location");
       JComboBox endCombo = new javax.swing.JComboBox();
       JTextPane endPane = new JTextPane();
     
           // Panel Creation
        JPanel firstRow = new JPanel();
        JPanel secondRow = new JPanel();
     
        // Panel for Fields and Buttons
        JPanel fieldPanel = new JPanel();
        JPanel buttonPanel = new JPanel();
     
        // Construct Labels and TextBoxes
        JLabel Miles = new JLabel("Miles planning to travel"         );
          JTextField distance = new JTextField(5);
        JLabel Fuelcost = new JLabel("What is the price per gallon/litre?"              );
          JTextField fuelprice = new JTextField(3);
        JLabel Total = new JLabel("Your total cost for the trip will be"            );
          JTextField totalcost = new JTextField(6);
        JButton submitButton = new JButton("Submit"); 
        JButton clearButton = new JButton("Clear Fields");
     
      //create the content pane
      public Container createContentPane()
      {
        //populate the JCombobox
        fuelCombo.addItem("Leaded");
        fuelCombo.addItem("Unleaded");
        fuelCombo.addItem("Super Unleaded");
        fuelCombo.addItem("Diesel");
        fuelCombo.addActionListener(this);
     
        startCombo.addItem("Minneapolis");
        startCombo.addItem("Duluth");
        startCombo.addItem("Bemidji");
        startCombo.addItem("Rochester");
        startCombo.addItem("Detroit Lakes");
        startCombo.addItem("St.Cloud");
        startCombo.addActionListener(this);
     
        endCombo.addItem("Daytona");
        endCombo.addItem("Darlington");
        endCombo.addItem("Las Vegas");
        endCombo.addItem("Talladega");
        endCombo.addItem("Richmond");
        endCombo.addItem("Chicago");
        endCombo.addActionListener(this);
     
        //construct and populate the north panel
        JPanel northPanel = new JPanel();
        northPanel.setLayout(new FlowLayout());
        northPanel.add(fuelPrompt);
        northPanel.add(fuelCombo);
        northPanel.add(beginningPrompt);
        northPanel.add(startCombo);
        northPanel.add(endPrompt);
        northPanel.add(endCombo);
     
        JPanel southPanel = new JPanel();
        southPanel.setLayout(new FlowLayout());
        southPanel.add(submitButton);
        southPanel.add(clearButton);
     
        JPanel centerPanel = new JPanel();
        centerPanel.setLayout(new FlowLayout());
        centerPanel.add(Miles);
        centerPanel.add(distance);
        centerPanel.add(Fuelcost);
        centerPanel.add(fuelprice);
        centerPanel.add(Total);
        centerPanel.add(totalcost);
     
     
         //createContainer and set attributes
         Container f = getContentPane();
         setLayout(new BorderLayout(40,40));
         fieldPanel.setLayout(new GridLayout(1,1));
         buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
         add(northPanel,BorderLayout.NORTH);
         add(southPanel,BorderLayout.SOUTH);
         add(centerPanel,BorderLayout.CENTER);
         setLocation(200,200);
         return f;
         }
         //main method executes at run time
         public static void main(String args[])
         {
           TripCalc f = new TripCalc();
           f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           f.setContentPane(f.createContentPane());
           f.setTitle("Trip Calculator"); 
           f.setSize(800,300);
           f.setVisible(true);
         }  
     
     
         // event to process user clicks
         public void actionPerformed(ActionEvent e)
         {
           String arg = e.getActionCommand();
         }
     
     
    }


    Ok. I've got this part all figured out now and the display is doing what I want it to do.

    Now if your wiling I need to code this so that when I select the various drop downs it will display my total costs. First I have to get the distance for all 6 drop down options and do all the calculations for that. I just may need a little help with certain aspects of it.

    Thanks so much for the help so far.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    when I select the various drop downs it will display my total costs.
    Can you explain the steps the code takes or should take and what the problems are?
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Nov 2012
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    It's supposed to calculate the total miles traveled by cost per gallon either manually input into the text field or using the dropdown for vehicle type. In essence user selects drop down for vehicle type and MPG is selected then drop down for fuel type it will auto fill the cost per gallon and the miles would be from starting location to ending location OR the person can enter that in manually with miles to travel and cost per gallon with vehicle type being used in the dropdown box.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    The steps the program needs to take could be:
    Gather the data needed
    compute the results
    display the results
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Nov 2012
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    Quote Originally Posted by Norm View Post
    The steps the program needs to take could be:
    Gather the data needed
    compute the results
    display the results
    I've got this part figured out from a previous assignment. What I haven't figured out is when I select say Bemidji to Darlington the coding to indicate that Bemidji was selected as the start and Darlington was selected as the ending location.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    when I select say Bemidji to Darlington the coding to indicate that Bemidji was selected as the start and Darlington was selected as the ending location.
    What happens when you select each of those items? Are the listeners called so that they can save what was selected?
    Or when do you determine what was selected?
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Nov 2012
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    the listeners are in the code, but that's the part I don't know is what or how to get the listener to "hear" what is being selected. I presume I add the code to this part "public void actionPerformed(ActionEvent e)
    {
    String arg = e.getActionCommand();
    }" but that's the part that has me currently stumped.

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trying to get two textBoxes and two JComboButtons to work with three dropdown boxes.

    In the listener you get a reference to the component that caused the event from the object passed to the listener. Cast that object to the type of component it is: say a combobox and then you can call its methods to see what was done, like what was selected.

    See the tutorial: http://docs.oracle.com/javase/tutori...nts/index.html
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. displaying data in 4 tier cascading dropdown list
    By javajobs29 in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: November 29th, 2012, 06:55 AM
  2. How to retrieve a selected value in dropdown using JSTL
    By abc21 in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: June 4th, 2012, 07:50 PM
  3. Strange boxes appearing
    By fishnj1333 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 11th, 2012, 05:36 AM
  4. [SOLVED] error adding textboxes to panel
    By macko in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 20th, 2011, 06:50 AM
  5. Button with Dropdown Menu?
    By Manish87 in forum Java Theory & Questions
    Replies: 2
    Last Post: February 14th, 2011, 01:05 AM