Summing up integers displayed in a textfield.

I have an applet where a user can place order(s) on the items displayed in a combobox. So I have a textfield that will show the price, another texfield that shows the total, a textarea that displays the user's order and a button called checkout.
Okay, here is my problem. When the user orders more than one item, and clicks on checkout, I want the total price of the items ordered to be displayed in the total texfield. So how do I do the sum to produce the total in the total field. Please note that the value of price changes based on the item the user is ordering. I will really appreciate it if anyone out there can assist. Thanks a lot in advance!!

Dr... I don't think I've ever seen you so snide... I like it :-)
OP: Well, that would really depend on what your textarea's contents look like...
Are you putting just some text:
thing 1 $4
thing 2 $5
thing 3 $4
If that's your text, and you want to pull that out... well, you could use a StringTokenizer to parse the lines and indexOf/substring on the line strings to find the price, then do the aforementioned arithmetic. But that isn't the easiest or most maintainable way...
Generally, I would say you should have a list objects which is your order. In the list, you put an object of a class called Product (or something similar) which has 3 fields (at least): ID, price, quantity. Generally, ID is some unique ID which is a key to another table of data which has name, description, etc.
So your text area is only used to display the list, which you could simply show by creating a text string based on those products. Or course, really, I would do a JTable to with a custom TableModel to show the Product list, but that's something you can save for later.
Anyway, you have this list of Product objects, and it'd be very easy with a for loop to go thru the list, add up all the product costs (total += (quantity * price)) and then display that total in the appropriate place.

Similar Messages

  • Format of sum of integers in sql query displayed in table as decimal

    I created a table with data from a RowSet. One of the columns is based on the sql sum function. The sum function is on a table column of integers (games.score) and is bound to a staticText column with #{currentRow.value['sum(games.score)']}
    Although this is a sum of integers the staticText component displays this in the table as a decimal--123.0 shows up in the column rather than the desired 123 when in design view. Can anyone tell me how to change this formatting from decimal to integer? I cannot see where to do this using the properties of a staticText component.

    Hi,
    You can try to convert your sum value to string directly into the sql statement.
    For example, in Oracle, to_char(sum(games.score)).
    I use this method to display short dates instead of sql timestamp in table columns: to_char(datefield, 'DD-MON-YYYY') as datefield.
    Hope this helps,
    Catalin Florean.

  • Total sum to be displayed in a table view control ?

    Hi,
      I am unable to display the total sum of a column in a table view control( using HTMLB ). How should one display the sum of a column ?
    THanks in advance,
    VaraPrasad

    Hi,
    it should work once you are restricting the capacity of the out put port then it should provide that much rows only otherwise its a Bug.
    Alternativily you are tellin to disaply using sorting then add a Sort operator to the output port and the display ur output port in down order.
    But first option should work just check it again.
    On which SP u r working?
    Regards,
    Govindu

  • How to display values in textfields obtained from another class

    Hi,
    Why, oh why, doesn't this work:
    When I select a row in my tableClass (consist of a JTable) I want to display these values (strings) in my TextFieldGUI class (consist of just JTextFields). My code looks like this:
    TableClass:
    public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {
        textFieldGUI = new TextFieldGUI() ;//reference to my textfield class
        gui = new mainGUI() ; //reference to my GUI class
        int tabbedIndex = gui.getSelectedIndex() ;
        int col = tableModel.getColumnCount() ;
        Vector string = new Vector() ;
        String empty = "" ;
        for(int index = 0; index < col ; index++){
            if(table.getValueAt(row, index) == null)
                string.addElement(empty) ;
            else
                string.addElement(table.getValueAt(row, index).toString()) ;
        if(tabbedIndex == 0){       
            System.out.println(string) ; //works fine
            textFieldGUI.setTextFieldValues(string) ;
    }TextField class:
    public void setTextFieldValues(Vector s){
        Vector string = new Vector() ;
        string = s ;
        System.out.println("TextFieldVector: " + string) ; //works fine as well
        String name = "" ;
        String dob = "" ;
        String web = "" ;
        name = string.elementAt(0).toString() ;       
        dob = string.elementAt(1).toString() ;       
        web = string.elementAt(2).toString() ;
        System.out.println("NAME: " + name +
                           ", BIRTH: " + dob +
                           ", WEB: " + web) ; //values are correctly printed
        txtName.setText(name) ; //writes nothing (empty)
        txtDob.setText(dob) ; //writes nothing (empty)
        txtWeb.setText(web) ; //writes nothing (empty)
    }Anyone got a hint on how I should svolve this one?
    thanks
    gmtongar

    Hi
    my problem is, for each job_id there is many users. Oh that's something completlty different...
    I Strongly Recommand to_
    1.*create 2 tables Jobs & users*
    2.*create a relation between them* 1 to many to get for each job more than a user that's the way that Must be -- execuse me the bad design of the db pulled u into this trap -
    3.then u can deal with it normally no need to a sample code but just a form with Jobs as  (Master) and Users as (detail) with a relation and with a simple query u can display each job_id is for many users.
    no null values no commas r needed.
    Hope this helps...
    Regards,
    Amatu Allah.

  • Change displayed text in textfield an space between elements

    Hey people,
    a have a Form based on a View. i want to change the spaces between some rows or elements (to group some elements) and don't know how.
    For example:
    Name Surname
    Birthday
    Phone Mobil
    City
    Between Birthday and Phone, and Phone and City now should be more space.
    I made it now like that:
    Birthday: Display --> rowspan --> 2
    and put an Element just shown as Text empty without label below "Birthday". But i don't like that because i need so much empty elements. Is there another possibility to change the style?
    I want to change the size from the displayed text in the textfields too, or make it bold maybe.
    I hope, i could make it comprehensible to you, if not ... just ask
    Greetings, Jana

    hey ageller,
    thank you very very much. that is exactly what i'm searched for ;-)
    can you tell me, if this doesn't work in firefox or mayby why? in IE 7 all works fine, but Firefox 2.0.0.6 doesn't show any changes.
    I cleared the cache but still no changes.
    Got the same problem with the width of my columns. In IE, Content is shown in one row and Firefox there is linebreak.
    Do you (or anybody else) know, how i can fix this??
    Thank you so far ....
    Jana

  • How to display names in textfield using ajax+flex

    HI, i want to display some names in a textfield like type
    forward that is if the user enter " a " in the textfield, the names
    starting with " a" has to display in drop-down list. how we can do
    this in flex?. please help me it is very critical for me.
    -- ss

    Hi Kiran,
    If you want to set the title only once in the application and if it remains same for rest of your app...you can simpley put pageTitle="Some Title" in your
    main Application Root tag..
    <mx:Application pageTitle="Some Title" />
    But if you want to change the title of your application frequently as you navigate through various screens in your app..then you can put a public function which chnages the title as I posted in my previous code and call that function from various screens by calling that public function using Application.application.setBrowserTitle(passmesage);
    Thanks,
    Bhasker Chari

  • How to display " ****" in a TextField?

    Hello,
    How do I make a TextField to behave like a password field. i.e when the user enters some text into it the textfield, the text should be displayed in the form of " ****** ". Can any one help me by giving some source code?
    Thanks
    [email protected]

    Kenny's idea is the easiest and best. If you have a reason that you don't want to do this, subclass JTextField, add a KeyAdapter, and whenever you get a key event of a character being entered, you can edit the contents of the text field using it's set methods.

  • Restricting input to integers, display with comma separators

    I'm using Acrobat 8 on a Macintosh. My question is very similar to the previous one about truncation. I have a small array that adds and subtracts fields, and sums them to totals. The following scripts restrict the data entry exclusively to numbers, but my problem is that it doesn't display my fields in Acrobat with comma separators, e.g., 123,456. Is there a better way of doing this, or is it just a matter of adjusting the formatting script?
    Using a custom script under Format:
    Custom Format script:
    event.value = "(" + eventvalue +")";
    Custom Keystroke Script:
    event.rc = /^[0-9]*$/.test
    (event.change);
    Bill Lomax

    I'm not aware of any cultures that allow multiple consecutive separators, and of course "en-US" certainly doesn't. I think you answer is just that TryParse isn't as smart as you would like it to be.
    If you know how many digits there are after the decimal point, you could use ToString to convert the decimal back to a string and verify that it is the same as the original string. For example, if the string has a currency symbol, thousands separators and
    two decimal places, you could use the following:
    Dim result As Decimal
    Decimal.TryParse(Me.tbxkWhCost.Text, System.Globalization.NumberStyles.AllowThousands _
    Or Globalization.NumberStyles.AllowDecimalPoint Or Globalization.NumberStyles.AllowCurrencySymbol, Nothing, result)
    If result.ToString("C2") = Me.tbxkWhCost.Text Then
    'String is good
    Else
    'String is bad
    End If
    I realise that this doesn't work if you don't know what format the number will be in.

  • Busy cursor - two cursors displayed over the TextField

    Hi all,
    first I describe the situation. When busy cursor is activated in Flex application, when the service is loading data from backend, then the clock or whatever you set can be displayed instead of the mouse arrow icon. But when you are over the TextField, then the busy cursor is displayed and over the busy cursor the additional "text input cursor" is displayed.
    1) Is it possible to get rid of that "text cursor" in the case when busy cursor is activated ? That means show only busy cursor like in other cases.
    2) Is it possible to override CursorManager ? As I did not found any events in the interface.
    Or what could be the solution to this ?
    I did not found any solution like this anywhere. I know how to set my own icon to the cursor, how to start and stop busy cursor manually. But how to override adding the text cursor to the scene only for the case when busy cursor is started and the Service is loading the items from backend and you are over some text component?
    thanks
    regards
    Michal.

    No, it's not mobile app.
    I use SDK 4.5.0
    By text components I mean TextInput for example, but it happens at all the places where "text cursor" is displayed.
    You can check the behavior in the following blog article, when you try the first example and press Toggle button to activate busy cursor and hover the text below. This is exactly what I want to avoid. Two cursors displayed. I don't know what is the version used in the article, but the same happens in 4.5.0
    http://www.flex-blog.com/set-busy-cursor-using-the-cursormanager/
    regards
    Michal.

  • Sum icon not display

    Dear All
    In my alv report  sum icon is not displayed in the  toolbar.
    Tell me the reason please.

    Hi ,
    IS there at least One Integer  cloumn or TYpe P column  . Then only it will show SUM symbol in alv grid toolbar  .
    also there should  be  assigned field catelog  to do_sum  .
    if ls_fieldcat-fieldname = 'THISFIELD'.
    ls_fieldcat-do_sum = 'X'.
    modify lt_fieldcat from ls_fielcat.
    endif.
    What will be use of SUM symbol if there is no Integer Field  or numeric field  ? .
    regards
    Deepak.

  • Sum values to display total (running total)

    I apologize for posting such a rudimentary question but I haven't been able to find an answer by searching the forum.
    Basically, I have several sensor inputs that are all factored into an equation that yeilds heat output (btu/hour). I need to take this value, which I have iterating once every second, and add it to itself every time it increments. In other words, say the first value is 10 (btus), the next second the value is 16, the code calculates and displays a value of 26 on the front panel and waits for the next second (or whatever iteration I choose) at which time it will add the new value to the running total.
    Thanks for your input
    Jake 
    Solved!
    Go to Solution.

    The Loopback function (<--) is basically a miniature shift register.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • Limit display length of textfield to 2 characters

    Hi,
    in my form i have a textfield for dayname like "Montag" which is german for Monday.
    On my form i do not have so much space therefore i want to show only "Mo" (first to characters).
    How can i acchieve this?
    Thank you
    Kind regards
    Manfred

    Hi Manfred,
    In Palletes select
    Objects (Tab) -> Field (tab) -> there is a check box 'Limit Length' . check that box  and enter 2 in the box 'Max Chars:'.
    Regards,
    Shaira Madhu

  • How to display a JClient LOV with a empty textfield at startup?

    Hi,
    we develop an application using JClient to connect a swing client to a bc4j middletier. In one special form consisting of three LOVs (3x label,textfield,button ->LovBinding) we want two of the LOVs to display a empty textfield when the form is opened the first time. The standard LovBinding shows the first row of the corresponding viewobject initially, pretending that the user already has chosen a value. Is there an (easy) way to override this behaviour?
    And what to do in the following scenario:
    The user chooses a value from a LOV, that value is displayed in the textfield. Now the user changes his mind and wants to be the LOV-textfield empty again. Currently there's no solution for this.
    We can think of several workarounds, but none of them seems to be a good solution...
    Any ideas for that?
    Thanks,
    Torsten

    Sorry, I try to be a bit more precise:
    It's not clear whether you want the "Lov dialog" to show no selection on startup or the form that uses the LOV to display nothing in the "textField" on >startup?
    Could you elaborate on this? A simple scenario may help. It's NOT the Lov dialog that should show no selection on startup. I wanted the textfield to display nothing, until I press the button which invokes the Lov dialog. The lov dialog allows me to select something and after pressing ok in the lov dialog I see me selection in the textfield.
    The scenario is the following:
    Imagine a form showing a combobox which allows the select a special type of value, does not matter. Additionally you have a lov combination consisting of a textfield and a button. The textfield should display a lookup value which can be selected via a lov dialog, which is invoked by the button.
    And you have a "calculate" button, which has no binding. This "calculate" button runs some kind of code that takes the value of the combobox and the value of the lov's textfield (if a value was chosen) and does something.
    The problem is the "if a value was chosen". I like to see an empty lov's textfield to indicate that nothing has been chosen solong. If I press the "calculate" button after choosing a value in the combobox and having nothing in the lov's textfield, the lov's textfield should be ignored by the following method.
    Again, if you are using JComboBox/JListBox for Lov, then the default windows key to clean selection is Ctrl+(Mouseclick on the selected row)
    If you want to display/allow no selection in the JULovButtonBinding's LovDialog, you pretty much have to do this by providing a custom LovPanel instead of >using the default one and implement the "no-selection" logic there.
    And in case of no-selection, set the currency on the LovRSI to no row (call reset()). Are there more shortcuts like Ctrl+MouseClick in JClient?
    Ok, what I intended was the following:
    We have the scenario described above. The user selects a combobox value, then opens the lov dialog by pressing the button, chooses some value and presses ok in the lov dialog. Now he sees his selection in the lov's textfield. But: he changes his mind and thinks it would be better to reset the lov's textfield to the empty state, before pressing the "calculate" button. Because there is no kind of reset for the lov's textfield, the user has no chance to do what he wants.
    Question is, can you think of an elegant way to solve this problem?

  • Sum Columns in a jTable?

    (Wasn't completely sure where to post this... but jTable is Swing, right?)
    I have a jTable displaying a database table containing integers corresponding to seats booked. I want to sum these integers in a final column.
    However, the table also contains Primary and Foreign key columns which are also integers. I don't want to sum these, obviously.
    Like this:
    PKey FKey1 FKey2    Col1  Col2  Col3  Col4  Total
    1    2     3        1     0     2     1     4
    2    3     3        1     1     2     2     6
    3    6     8        1     3     1     1     6However, I really haven't been doing this very long, and have no idea where/how to sum these values. Do I write some kind of renderer? Can I do some kind of "int Total = Col1+Col2... etc;"? Or do I sum the values on a lower level and then display the result in the table? In other words: "Help! I'm lost!"

    Well you would probably calculate the total as you first populate the TableModel.
    Then if you data changes dynamciallly you would use a TableModelListener to recalculate the total. Here is a simple example:
    [http://forums.sun.com/thread.jspa?forumID=57&threadID=566133]

  • Price not getting displayed in next page

    ok this is very simple, i don't know y it is not working
    i m calculating my price in shoppingcart.jsp and then i want to show it as hidden value in form.jsp, i m getting null in form.jsp
    <input type="hidden" name="textfield" value="<%=sum%>"  />////in shoppingcart.jsp
    <%=request.getParameter("textfield")%> ////in form.jsp

    ok this is very simple, i don't know y it is not
    working
    i m calculating my price in shoppingcart.jsp and then
    i want to show it as hidden value in form.jsp, i m
    getting null in form.jspYou might have a better chance of getting a response by posting this in the JavaServer Page (JSP) forum here.

Maybe you are looking for

  • Bug report (and solution): adding multiple records through Java API in bulk

    I have found some bugs in the Java API (version 4.1.25) that makes it impossible to add mulitple values in bulk to a RECNO database. The fixes are as follows: MultipleEntry.java, line 80: "DbUtil.int2array(curr_off, this.data, pos);" should be replac

  • HELP....New I-tunes 7.7 has lost my file connections

    i downloaded 7.7 the other day, and after that, I cant play but maybe 10% of my music. The songs that I cant play, I get an exclamation point and a message that says I need to locate the folder, Yet I dont know where to look !! All the song titles ar

  • Crash and video garbage on K2M2

    I need help, I think that I have a bad k2m2 combo board. I have read through most of the forum and can't find any similar problem. I am not a newbie, I have seen this problem on an ASRock once before but RMA'd that board. But after getting an MSI, I

  • Upgraded outdoor 1310G bridge from Autonomous to LWAPP

    I recently got a pair of outdoor 1310G bridge radios to create a bridge. I upgraded one of the APs from Autonomous to LWAPP so that it could connect to our 4402 controller so that it could be monitored and controlled by it. Everything looks like it u

  • Best approach to upgrade MaxDB AND move to new OS release

    What would be the best approach to upgrade Contentserver MaxDB 7.5 on W2K server (32-Bit) to MaxDB 7.7 on Windows 2008 Server x64 (R2?)? 1.  a) Upgrade MaxDB on the existing installation      b) Create a complete backup      c) Install latest release