Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


joseph merriex
combo boxes
0 Answer(s)      3 years and 7 months ago
Posted in : Java Beginners


how do you store numbers in the choices. ex. soda is $.75 and tax is $.07 then it equals a new total. I've been trying to use the Itemlistener but i can't figure out how to store the numbers

import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.ButtonGroup; import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JRadioButton; import javax.swing.JTextField;

import javax.swing.WindowConstants; import javax.swing.SwingUtilities;

public class BurgeMenu extends javax.swing.JFrame implements ItemListener
{ private JLabel jLabel1; private JLabel jLabel2; private JLabel jLabel3; private JLabel jLabel4; private JLabel jLabel5; private JRadioButton jRadioButton5; private JRadioButton jRadioButton4; private JRadioButton jRadioButton3; private JRadioButton jRadioButton2; private JRadioButton jRadioButton1; private ButtonGroup buttonGroup1; private JTextField totalbox; private JTextField taxbox; private JTextField subtbox; private JButton jButton1; private JButton jButton2; private JLabel jLabel8; private JLabel jLabel7; private JLabel jLabel6; private JComboBox jComboBox2; private JComboBox jComboBox1; private JTextField sprqst; double Cheeseburger = 2.49; double DoubleCheeseburger = 3.89; double TripleCheeseburger = 4.99; double Medium = .75; double Large = 1.25; double tax = .07; double subtotal; double total;

/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            BurgeMenu inst = new BurgeMenu();
            inst.setLocationRelativeTo(null);
            inst.setVisible(true);
        }
    });
}

public BurgeMenu() {
    super();
    initGUI();
}

private void initGUI() {
    try {
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(null);
        {
            jLabel1 = new JLabel();
            getContentPane().add(jLabel1);
            jLabel1.setText("McDowell's");
            jLabel1.setBounds(204, 0, 125, 30);
        }
        {
            jLabel2 = new JLabel();
            getContentPane().add(jLabel2);
            jLabel2.setText("ComboMeal");
            jLabel2.setBounds(24, 43, 90, 16);
        }
        {
            jLabel3 = new JLabel();
            getContentPane().add(jLabel3);
            jLabel3.setText("SpecialRequest:");
            jLabel3.setBounds(24, 76, 129, 16);
        }
        {
            jLabel4 = new JLabel();
            getContentPane().add(jLabel4);
            jLabel4.setText("Drinks:");
            jLabel4.setBounds(24, 110, 72, 16);
        }
        {
            sprqst = new JTextField();
            getContentPane().add(sprqst);
            sprqst.setBounds(171, 73, 158, 22);
        }
        {
            ComboBoxModel jComboBox1Model = 
                new DefaultComboBoxModel(
                        new String[] { "1.Cheeseburger", "2.Double Cheeseburger","3.Triple Cheeseburger" });
            jComboBox1 = new JComboBox();
            getContentPane().add(jComboBox1);
            jComboBox1.setModel(jComboBox1Model);
            jComboBox1.setBounds(171, 36, 166, 22);
            jComboBox1.addItemListener(this);
        }
        {
            jLabel5 = new JLabel();
            getContentPane().add(jLabel5);
            jLabel5.setText("Size:");
            jLabel5.setBounds(24, 163, 56, 16);
        }
        {
            ComboBoxModel jComboBox2Model = 
                new DefaultComboBoxModel(
                        new String[] { "Small", "Medium","Large" }); 

            jComboBox2 = new JComboBox();       
            getContentPane().add(jComboBox2);
            jComboBox2.setModel(jComboBox2Model);
            jComboBox2.setBounds(171, 160, 132, 22);
            jComboBox2.addItemListener(this);
        }
        {
            jLabel6 = new JLabel();
            getContentPane().add(jLabel6);
            jLabel6.setText("Subtotal:");
            jLabel6.setBounds(24, 205, 72, 16);
        }
        {
            jLabel7 = new JLabel();
            getContentPane().add(jLabel7);
            jLabel7.setText("Tax:");
            jLabel7.setBounds(24, 245, 56, 16);
        }
        {
            jLabel8 = new JLabel();
            getContentPane().add(jLabel8);
            jLabel8.setText("Total:");
            jLabel8.setBounds(24, 288, 56, 16);
        }
        {
            jButton1 = new JButton();
            getContentPane().add(jButton1);
            jButton1.setText("Submit Order");
            jButton1.setBounds(171, 324, 117, 22);
        }
        {
            jButton2 = new JButton();
            getContentPane().add(jButton2);
            jButton2.setText("Clear");
            jButton2.setBounds(316, 324, 71, 22);
        }
        {
            subtbox = new JTextField();
            getContentPane().add(subtbox);
            subtbox.setBounds(171, 202, 68, 22);
        }
        {
            taxbox = new JTextField();
            getContentPane().add(taxbox);
            taxbox.setBounds(171, 242, 68, 22);
        }
        {
            totalbox = new JTextField();
            getContentPane().add(totalbox);
            totalbox.setBounds(171, 285, 68, 22);
        }
        {
            jRadioButton1 = new JRadioButton();
            getContentPane().add(jRadioButton1);
            jRadioButton1.setText("Coke");
            jRadioButton1.setBounds(171, 108, 60, 20);
            getButtonGroup1().add(jRadioButton1);
        }
        {
            jRadioButton2 = new JRadioButton();
            getContentPane().add(jRadioButton2);
            jRadioButton2.setText("Sprite");
            jRadioButton2.setBounds(171, 131, 64, 20);
            getButtonGroup1().add(jRadioButton2);
        }
        {
            jRadioButton3 = new JRadioButton();
            getContentPane().add(jRadioButton3);
            jRadioButton3.setText("Diet Coke");
            jRadioButton3.setBounds(236, 108, 85, 20);
            getButtonGroup1().add(jRadioButton3);
        }
        {
            jRadioButton4 = new JRadioButton();
            getContentPane().add(jRadioButton4);
            jRadioButton4.setText("Root Beer");
            jRadioButton4.setBounds(235, 131, 82, 20);
            getButtonGroup1().add(jRadioButton4);
        }
        {
            jRadioButton5 = new JRadioButton();
            getContentPane().add(jRadioButton5);
            jRadioButton5.setText("Orange");
            jRadioButton5.setBounds(321, 108, 68, 20);
            getButtonGroup1().add(jRadioButton5);
        }
        pack();
        this.setSize(500, 402);
    } 
    catch (Exception e) 
    {
        //add your error handling code here
        e.printStackTrace();
    }
}

private ButtonGroup getButtonGroup1()
{
    if(buttonGroup1 == null) 
    {
        buttonGroup1 = new ButtonGroup();
    }
    return buttonGroup1;
}

public void itemStateChanged(ItemEvent event) 
{
     if( event.getStateChange( ) == ItemEvent.SELECTED)
            subtbox.setText("");
     else if( event.getStateChange( ) == 1)
            subtbox.setText("Cold");
  }

}


Advertisement
View Answers

Related Tutorials/Questions & Answers:
combo boxes
combo boxes  how do you store numbers in the choices. ex. soda is $.75 and tax is $.07 then it equals a new total. I've been trying to use the Itemlistener but i can't figure out how to store the numbers import javax.swing.
values of Combo boxes are not stored in database - JSP-Servlet
values of Combo boxes are not stored in database   i have some combo box values. when i click the submit button after select combo box values...) { document.getElementById('combo').style.visibility = 'hidden'; } } function call
Advertisements
Handling multiple combo boxes of same name - IDE Questions
Handling multiple combo boxes of same name  my code is like this.. i'm...' combo. i want no. of 'csubject' on the browser.. I hope.. i'll get solution
combo box
combo box  Hi, [_|] dropdown box [ ] [INCLUDE] [ ] | | [INCLUDE All
combo box connection
combo box connection  how to provide connection between three combo boxes,if my 1st combo box is course and 2nd combo box is semester and 3rd combo... combo boxes.   Here is Java swing code: import java.sql.*; import
combo box - JSP-Servlet
combo box  how to get a combo box in jsp page which allows editing as well as list box
populate Combo Box dynamically
populate Combo Box dynamically  Hi, How to populate the Combo Box dynamically using Flex with Jsp's
JavaScript Dynamic Combo Box
JavaScript Dynamic Combo Box Here we are going to create dynamic combo box. For this, we have created two combo boxes where combo1 represents countries and combo2 represents the cities. The values of the combo boxes are stored
Label.setText showing square boxes for non english locales
Label.setText showing square boxes for non english locales  Hi, I am using Label.setText to display a value in applets of the application by fetching... are getting displayed as square boxes when locale is passed other than english locale
date in combo box
date in combo box  strong texthello, how can i desplay the current year and next year in combo box???!!! it must be uppdate atumaticaly every year>>>
assigning arraylist to combo box
assigning arraylist to combo box  Hi I am busy coding the Airline Reservation program, i have an arraylist of locations which i want to assing to the combo box. please help
How to Create Pop Up Boxes in JavaScript
How to Create Pop Up Boxes in JavaScript  Hi, I am beginners...,   Hi, In JavaScript you can find three types of pop alert boxes. These are alert, confirm, prompt pop up boxes found in JavaScript. You are asking how
java combo box
java combo box  how to display messagedialogbox when the combobox is null, Thanks in advance
How to change focus among multiple select boxes?
How to change focus among multiple select boxes?  Hello, I have three select boxes in three divs. All of the select boxes are focused when I click... boxes aren't focused at one click in my example. I have to click twice. Maybe, my
Hide boxes by clicking on it using jQuery
Hide boxes by clicking on it using jQuery In this tutorial , we will discuss about how to hide boxes by clicking on it using jQuery. In the given below example , 30 boxes inside web page are displayed. When we click on any box (among
JavaScript Pop Up Boxes
JavaScript Pop Up Boxes JavaScript has three kind of pop-up boxes,  i)    Alert-Box: If some surety is required from the user or an alert message is to generate then we can use alert box, user has to click ok
Check boxes - Java Server Faces Questions
Check boxes  Hi All, In Jsf when i select one item in selectOneMenu it should display check boxes according to our requirement.for Ex:if i select one item state it should display cities in checkboxes.there we have to select
DropDown and text boxes with AJAX, JSP - Ajax
DropDown and text boxes with AJAX, JSP  Hi, we are using one drop down and two text boxes. Drop down values needs to be retrive from one table.we... in the text boxes onblur it needs to validate whether the inserted values
Disable of Combo - JSP-Servlet
am giving grading facility to the user. Once user selected his grade in combo , the combo should be disabled auotmatically. It should not get enabled at any... combo once grade selected.... pleas help me regarding this aspect.... Thanks
Combo Box - Struts
Combo Box  I hava acombo box cnnected to my database via html collections. When selecting an option, i want to display specific parts (sectons) on my web page....am trying to use logic:present and logic:empty but its not working
How to create Combo Box in SWT
How to create Combo Box in SWT       This section illustrates you how to create a combo box. In this example, we have created two different combo boxes where one is performing
combo box - JSP-Servlet
combo box  I am using a JSP form in which a combobox is given and I want to populate data in it from database and on the basis of yhe selected item I want to display related data in a textbox  Hi Friend, Create
combo program - Java Beginners
combo program  I want to give DOB in combo box for that i have to give 1 to 30 for days and 1900 to 2010. Without giving all, using for loop i have to get the values. Please help me..   Hi Friend, Please visit
populating the combo box - Struts
populating the combo box  Hi I am having problem populating the combo box with a table in MS SQL Server 2005 Management Studio Express. Belo is the extract from the Struct?jsp application. Sector
Helps with combo box and frame
Helps with combo box and frame  Hi i have a combobox and when i click... on the second window and click confirm i would have the information on the combo box. i... combo; JTextField txtBox; private String PersonViewing; private String
combo box value
combo box value   i want to populate one combo box value based on another combo box value using ajax   1)country.jsp: <%@page import="java.sql.*"%> <html> <head>
combo box value
combo box value   i want to populate one combo box value based on another combo box value using ajax   1)country.jsp: <%@page import="java.sql.*"%> <html> <head> <script language
Problem With Combo Box Editable Property
Problem With Combo Box Editable Property  Hi I am new To Flex i had set Combo Box Editable Property as true. But I didn't get the property filtering in the combo box like when you enter text "S" in the combo box then the names
Loading combo box from oracle
Loading combo box from oracle  how can i load values into a combobox from oracle database when a value is selected in another combo box
jtable combo - Java Beginners
jtable combo  i am using jtable (using defaulttablemodel) ,when i am click on a particular cell of jtable i want to display the combo box in that cell,plz provide program  Hi Friend, Try the following code: import
combo box code problem
combo box code problem  in this my problem related to : when i select state MP then i wil open the its corresponding city but in database it only stores the option value no like MP at option value 10 then it will stores the 10
The easy slider plug-in implementing with numeric boxes
The easy slider plug-in implementing with numeric boxes In this tutorial... using easySlider function of jQuery. The numeric boxes highlighted according... the boxes highlighting : Download Source Code   Click here to see
WRITE A CODE IN STRUTS ACTION CLASS FOR CHECK BOXES AND RADIO BUTTONS - Struts
WRITE A CODE IN STRUTS ACTION CLASS FOR CHECK BOXES AND RADIO BUTTONS ... for check boxes and radio buttons and for submit buttons. i have a jsp page which contains check boxes,radio buttons.and when i click submit button the related
Dojo Combo Box
Dojo Combo Box          In this section, you will learn what is combo box and how to create a combo box in dojo. For creating the Combo box  you need "
enabling parts of a search button based on the ssn boxes filled.
enabling parts of a search button based on the ssn boxes filled.  I want to do an AJAX program to search a particular ssn. Currently I have ssn field with 3 text boxes and a search button to search the particular ssn. I want
Combo box value Error - WebSevices
Combo box value Error   if($_SERVER['REQUEST_METHOD'] == 'POST' ) { $visa =trim($_POST['hdVisa']); } document.frmProposal.hdVisa.value = document.getElementById('cmbVisa').value; Error
Populate a combo box using data from a database
Populate a combo box using data from a database  Hi Guys, In need of some help, so i have three combo boxes, the first is supplier, the second... combo box which will then load the next combo box values, now i know how
how to create a combo box in html
how to create a combo box in html  <tr> <td>Number<span class=mandatory>*</span></td> <td> <select name="number" id="course" style="width:158px;"> <option value="none">----Select
Retrieving Data from Database to fill Combo Box
Retrieving Data from Database to fill Combo Box  Sir, I have a JSP Page with a combo box and a label. I have a database that has two fields id and an image. Now I want to fill the combo box with image and on selecting
Validate 2 list boxes, one is multiselect, one is singleselect
Validate 2 list boxes, one is multiselect, one is singleselect  <head> <script language="javascript"> function validateListBox(){ var lb = document.getElementById('mySelect
how to get selected name from combo box
how to get selected name from combo box   i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz
how to get selected name from combo box
how to get selected name from combo box   i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
Combo Box operation in Java Swing
Combo Box operation in Java Swing   ... the Combo Box component, you will learn how to add items to the combo box, remove items from the combo box. This program shows a text field, a combo box
loading value into combo box by selecting value from other combo box - JSP-Servlet
loading value into combo box by selecting value from other combo box  ... is that as i select state from state_combo_box,then the next combo box is dynamically loaded with only district corresponding to "selected state "....and 3rd combo
JSP combo and text field related questio
JSP combo and text field related questio  in JSP,i had stored data from database in a textboxes usin combo..now i want to use these values of text fields into another page(next page)..i tried it by using request.getparameter
how to dynamically add text boxes with add and remove link based on drop down choices, if a particular choice is selected.
how to dynamically add text boxes with add and remove link based on drop down choices, if a particular choice is selected.  how to dynamically add text boxes with add and remove link based on drop down choices, if a particular
how to get combo box value - JSP-Servlet
how to get combo box value  i have created 1 servlet & 1 jsp page. in servlet page i have fired query & fetched name & its id & that i have shown in combo box in jsp page: (small part of my code) "> now i want
Advertisements
 

 

 

DMCA.com