Assign integer to value typed in jtextfield

Hello I am having trouble with basics.
i have a jtext field private JTextField  theAmountOfStock   = new JTextField();and later on an integer which is assigned a value of 1 int    amount = "1";I don't want the integer to be 1 I want it to be what ever the user types in to the jtextfield, could anyone give me advice on how to do this? help much appreciated.

thanks for not being patronising, i hav only just
started learning java. Therefore i'm still not
understanding (please forgive my incompetence)Important skills you have to master:
- break up a problem into steps. You don't want to assign an int from a text field. You want to get the field's contents, and you want to change a String into an int.
- Read the API. I didn't use proper capitalization - look at the Integer class
- Use the search. There must be thousands of posts that explain how to convert a String to an int. I think I posted one before, today.
I apologize for sighing, it was mostly related to part 2 and using a text area without knowing how to get its contents. The API should be the first thing to refer to before using a class.

Similar Messages

  • Assigning a binary value to an integer

    Hi, I am trying to assign a binary value in my program to an integer. In some assembly languages you would do the following:
    mov a, 00010101b
    for binary and for hex:
    mov a, 0E2h
    In java, you can assign a hex value with:
    int a=0x3F;
    What should I do to assign a binary value? Is it possible?
    Regards... Martin Schmiedel

    The static method parseInt in the java.lang.Integer class can be used to convert a String representing a binary number into its decimal integer value. In addition to the string representing the number, you also pass in an integer representing the radix, which for binary would be 2, hex would be 16, etc. So for example:
    int x = Integer.parseInt("00010110", 2);
    Is that what you're trying to do? Cheers,
    Chris

  • Getting values from a JTextField on a JPanel in another class

    I have created a class which extends a JPanel and added a JTextField to it, which has an addActionListener for getting the values typed in the JTextField. I want to use the class created in another class and retrieve the values typed in the JTextField, so how do i go about that? I have the class created below so the problem is how to retrieve content of val[val] in another class?
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class TextFieldChooser extends JPanel{
      int val;
      public TextFieldChooser(String str){
        val = 0;     
        setLayout(new FlowLayout());
        add(new JLabel(str));
        JTextField txtf = new JTextField(5);
        txtf.addActionListener(new TextFieldListener());
        add(txtf);
      }//end constructor     
      private class TextFieldListener implements ActionListener{
        public void actionPerformed(ActionEvent e) {
           val = Integer.parseInt(e.getActionCommand());
      }//end text field listener
      public int getValue(){
        return val;     
    }//class

    The problem is which listener can be programmed to handle the event performed on the class TextFieldChooser in the other class?
    I have created a class which extends a JPanel and
    added a JTextField to it, which has an
    addActionListener for getting the values typed in the
    JTextField. I want to use the class created in
    another class and retrieve the values typed in the
    JTextField, so how do i go about that? I have the
    class created below so the problem is how to retrieve
    content of val[val] in another class?
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class TextFieldChooser extends JPanel{
    int val;
    public TextFieldChooser(String str){
    val = 0;
    setLayout(new FlowLayout());
    add(new JLabel(str));
    JTextField txtf = new JTextField(5);
    txtf.addActionListener(new TextFieldListener());
    add(txtf);
    }//end constructor
    private class TextFieldListener implements
    s ActionListener{
    public void actionPerformed(ActionEvent e) {
    val = Integer.parseInt(e.getActionCommand());
    }//end text field listener
    public int getValue(){
    return val;
    }//class

  • Assigning strings a value?

    I had another problem with nested if structure, i have tried ever way i could think of possibly to assign the value to a string. hard to explain, example below
    //classCode is input from user
    // classYear is the current year in highschool, i keep on getting errors no matter which way i assign the string!
    i'm trying to figure out how to do this correctly
    If(ClassCode = ("FR") // i know it's not correct, but i have no idea classyear= "Freshman"; // what is? same for this assignmeny!
    If(grdP = 100)
    grade = "A"; // results in a error, i'm real confused

    Try using a switch statement to solve your problem. It'll be cleaner code and easier to read and understand.
    //declare a variable
    int usrInput;
    if( ( usrInput >= 10 ) || ( usrInput <= 1 2) )
    switch(classYear)
    case 10:
    classyear = "Freshman";
    case 11:
    classyear = "Sofmore"; etc.
    Not sure if this will help but here's a project that I worked on for a class and it was assigning a string value to a variable. I used a switch statement (do you know what those are?) to determine which value was selected.
    I know this is a bit long but I think it's easy enough to understand. You will have to determine what value you want to put in your if statement. Switch does not use Strings so you'll have to use an integer to determine what is selected.
    import java.text.NumberFormat;                              // Java core packages
    import java.util.Locale;
    import javax.swing.JOptionPane;                              // Java extension packages
    public class A4_512                                             // begin class definition
                                                                     // main method begins execution
                                                                     // of Java application
         public static void main( String args[] )
              int     counter,                                        // counter variable
                   itmSold,                                        // holds usrInput for product sold as int data type
                   qtySold = 0;                                   // holds usrInput for quantity sold as int data type
         double     itmValue = 0.00,                              // value of item sold
                   totSales = 0.00;                              // total value of items sold
         String     usrInputItm = "",                              // holds usrInput for product sold as int String type
                   usrInputQty = "",                              // holds usrInput for product sold as int String type
                   currDay = "",                                   // String value for current day
                   results = "";                                   // holds output results
                                                                     // Begin counter controlled loop
              for( counter = 0; counter <= 6; counter++ )
                   switch ( counter )                              // Begin switch statement to determine day of the week
                        case 0:
                             currDay = "Sunday";
                             break;
                        case 1:
                             currDay = "Monday";
                             break;
                        case 2:
                             currDay = "Tuesday";
                             break;
                        case 3:
                             currDay = "Wednesday";
                             break;
                        case 4:
                             currDay = "Thursday";
                             break;
                        case 5:
                             currDay = "Friday";
                             break;
                        case 6:
                             currDay = "Saturday";
                             break;
                                                                     // prompt for input and read
                                                                     // product number then convert
                                                                     // data type to integer data type
                   usrInputItm = JOptionPane.showInputDialog(
                        "Please enter a product number purchased on " + currDay + "\n\n Enter 0 to enter data for next day." );
                   itmSold = Integer.parseInt( usrInputItm );
                   while( itmSold != 0 )                         // Begin sentinel control while loop
                                                                     // if statement to determine correct product number entered
                        if( ( itmSold > 5 ) || ( itmSold < 0 ) )
                                                                     // display error message
                             JOptionPane.showMessageDialog ( null, "You must enter product number from 1 through 5.\nPlease try again.",
                                  "Wrong Product Number Error", JOptionPane.ERROR_MESSAGE );
                                                                     // prompt for input and read
                                                                     // product number then convert
                                                                     // data type to integer data type
                             usrInputItm = JOptionPane.showInputDialog(
                                  "Please enter a product number purchased on " + currDay + "\n\n Enter 0 to enter data for next day." );
                             itmSold = Integer.parseInt( usrInputItm );
                        else
                             switch ( itmSold )               // begin switch statement to determine value of itmSold
                                  case 1:
                                       itmValue = 2.98;
                                       break;
                                  case 2:
                                       itmValue = 4.50;
                                       break;
                                  case 3:
                                       itmValue = 9.98;
                                       break;
                                  case 4:
                                       itmValue = 4.49;
                                       break;
                                  case 5:
                                       itmValue = 6.87;
                                       break;
                             }                                        // end switch statement
                                                                     // prompt for input and read
                                                                     // quantity sold then convert
                                                                     // data type to integer data type
                             usrInputQty = JOptionPane.showInputDialog(
                                  "Please enter quantity sold on " + currDay );
                             qtySold = Integer.parseInt( usrInputQty );
                             totSales += itmValue * qtySold;
                                                                     // prompt for input and read
                                                                     // product number then convert
                                                                     // data type to integer data type
                             usrInputItm = JOptionPane.showInputDialog(
                                  "Please enter a product number purchased on " + currDay + "\n\n Enter 0 to enter data for next day." );
                             itmSold = Integer.parseInt( usrInputItm );
                        }                                             // end if statement to determine correct product number entered
                   }                                                  // end while statement
              }                                                       // end for loop
                                                                     // set currency format for output
              NumberFormat moneyFormat =
                   NumberFormat.getCurrencyInstance( Locale.US );
                                                                     // add total to results
              results = "Total Sales for the week: " + moneyFormat.format( totSales );
                                                                     // show output
              JOptionPane.showMessageDialog ( null, results,
                   "Results", JOptionPane.PLAIN_MESSAGE );
              System.exit( 0 );                                   // terminate application
         }                                                            // end main method
    }          // end class definition

  • Assigning a default value to a field

    Hello Everyone,
           Could you please tell me how to assign a default value to a field in a transparent table, so that while creating an entry even if we don't enter the value, a default value will be assigned.
    Thanks,
    Anbu.

    Like this
    DATA: BEGIN OF itab OCCURS 0,
            field1 TYPE c VALUE 'X'
            field2 TYPE c,
          END OF itab.
    append itab.
    append itab.
    You will have by default X set in both rows for field1.
    Regards
    Marcin
    PS: Ooops I just noticed you meant transparent table but I wrote about internal one. As long as you maintain that table using maintenance view you can use event 05 - When Creating a New Entry and set fixed value for a field there. So whenever you create new entry it will receive that value.
    Edited by: Marcin Pciak on Jun 23, 2010 8:57 AM

  • Assigning a node value from an XML variable to a String type  in Weblogic Process Integrator

    Hi,
    Is there any way to assign a node value from an XML variable to a String variable
    in Weblogic Process Integrator...
    Thanx.
    Narendra.

    Nerendra
    Are you talking about using Xpath on the XML document and assigning to a
    variable, it is unclear what you are asking
    Tony
    "Narendra" <[email protected]> wrote in message
    news:3bba1215$[email protected]..
    >
    Hi,
    Is there any way to assign a node value from an XML variable to a Stringvariable
    in Weblogic Process Integrator...
    Thanx.
    Narendra.

  • Assigning a javascript value to a JSP variable

    How do i assign a javascript value to a JSP variable?
    eg
    <%
    String JSPvar;
    %>
    <script language="JavaScript1.2">
    <!--
    var javascriptVar="hey"
    -->
    </script>
    <%
    JSPvar = javascriptVar ???
    %>

    You do know that the JSP runs on the server and generates HTML, including Javascript, that is executed on the client, don't you?

  • How to send timer job email to "assigned to" feild value in a task list?

    Hi All,
    How to send timer job email  to "assigned to" field value in a task list if due date is after two days from now?

    Create a SharePoint Designer Workflow and use "pause until date" option when an new item is created/update.
    Using Server Object model, I believe you can create the timer job from item event receiver.
    --Cheers

  • How to Assign a Constant Value to a Dim. Member when pulling Master Data?

    BPC Gurus:
    I am trying load Vendor and Customer Master data into BPC dimension.  My Dimesnion has memebrs: ID, EVDESCRIPTION, PARENTH1, TYPE.  I have successfully pulled the ID and the description from 0CUSTOMER and 0VENDOR.  However, I
    need to have a ttext value for 'PARENTH1' and 'TYPE'.  For Customers, I want to add a FIXED value "'CUSTOMER' for every
    Customer ID pulled in and also for "TYPE", I want a value of "CUSTOMER".  When I maintainthe Dimension, I want to see
    th followingvalues:
    ID                          EVDESCRIPTION                                   PARENTH1                         TYPE
    0000000001         WALMART                                            CUSTOMER                        CUSTOMER
    0000000002          TARGET                                               CUSTOMER                        CUSTOMER
    and so ON
    Since we have Vendor Numbers in the same Diemsnion, when I pull Vendors, I need to have similar values as:
    ID                          EVDESCRIPTION                                   PARENTH1                         TYPE
    0000005050         ABC Supply Inc.                                   VENDOR                            VENDOR
    0000005051         BASF                                                    VENDOR                            VEDOR
    and so ON
    How can assign a Fixed value to the member Propert?  Can I achieve it in Conversion file....? 
    ( My atempts failed...).
    Any suggestion recommendation would be gretaly appreciated.
    Munna.

    Hi,
    For adding fixed values to the properties, you can use the transformation file. In the mapping section, you can specify a constant value. This value will be written to properties of all the members while importing master data. However, for parenth, its a bit different. First thing is that, you need to have a member called CUSTOMER, then only you can have CUSTOMER in the parenth column. Even if you add it and use the mapping section for this purpose, then it will write CUSTOMER to parenth for all the members (even to CUSTOMER member). And this will be wrong. So, you will need to write it manually.
    Hope you got the idea.

  • Can't assign a string value to a member of type TEXT in Calculation Manager

    I can assign a string value to that member of type TEXT using a run-time prompt of type StringToNumber.
    Example: "My Text Member" = {string_rtp};
    However, I need to accompllish the same function without using a run-time prompts.
    I have a planning application and I know that text along with all other non-numeric
    values are stored on the relational side in the planning application schema.
    It seems reasonable to assume that if this can can accomplish
    with a run-time prompt that I could do also do it without a run-time prompt.
    What appears to be lacking is a function like:
    "My Text Member" = @StringToNumber(<String Literal>);
    Clearly, this is already being done "under the covers" for run-time prompts. If
    would appear to be a minor enhancement to expose such a function to developers.
    NOTE: I suppose you would also need to add new syntax/function to identify a string
    literal from say a member name. I'm wondering if this is the more difficult challenge
    from a product perspective????

    When executing a Calculation Manager rule in Planning, the run-time prompt (RTP) is populated by looking up the outline information present in the relational Planning application database. If the RTP is of type TEXT, the strings displayed in the member select are from the from the relational Planning application database too. Subsequently when executing the Rule, the RTP's value is in fact the record ID (a number) which is then saved into the appropriate intersection in Essbase.
    You need to bear in mind, the Rule is executed in Essbase. If Essbase needs to "write" a text, it would then need to connect to the Planning relational database to create a new record. The newly created record ID then needs to be feed back to Essbase, in order to store it in the appropriate intersection.
    What you are suggesting, comes with a big overhead causing Essbase and the rule to slow. Thus, the disadvantages outweighs the advantages.

  • How to assign a default value to a column ?

    Hi
    In the Object browser is it possible to modifiy a column in order to assign a defalut value to the column ?
    I have a table FICHE in which I want to assign a default value 0 to a column which type is NUMBER.
    Thank you for your kind answers.
    Christian.

    Hi Christian
    For one reason or the other you can't do that using 'Create Column' or 'Modify Column'. You can only do that by issuing a SQL command : alter table fiche modify column( <column name> default 0)
    HTH
    Roel

  • How to assign a default value when there is no prompted value

    Dear all,
    I create a filter and it's value is relate to a prompt.If the prompt is not fill I found that all record is selected.
    How did I assign a default value so that when I didn't fill some value in to the prompt and still can get the result by
    the default value I set?
    Thanks a lot!

    Are you using dates for between or some character column?
    Post your example.
    Instead of between use to is equal prompts, so u will have then 2 fields one for date from a nd one for date to. Everything is the same as I wrote just repeat steps...
    You must put 2 separate fields if you are using date between and you want to have default variable for both.
    Column formula for the first calendar date prompt:
    case when 1=2 then TIMES.TIME_ID else cast ('1.1.1900' as date) end
    and for the second:
    case when 1=2 then TIMES.TIME_ID else cast ('1.1.2900' as date) end
    Now you set up default repository variable for both prompts.
    Presentation variable you put in the set presentation variable on each prompt:
    p_date_from
    p_date_to
    And in Answers filter will be like this:
    *TIMES.TIME_ID between @{p_date_from}{VALUEOF("rv_test_date_to_char")} and @{p_date_to}{VALUEOF("rv_test_date_to_char")}*
    or you can put a different default variables
    *TIMES.TIME_ID between @{p_date_from}{VALUEOF("rv_test_date_to_char_from")} and @{p_date_to}{VALUEOF("rv_test_date_to_char_to")}*
    I posted similar in my blog:
    Date between in filter and title when using presentation variable from calendar dashboard prompt or drop-down list in OBIEE
    http://108obiee.blogspot.com/2009/03/date-between-in-filter-and-title-when.html
    Regards,
    Goran O
    http://108obiee.blogspot.com
    Edited by: Goran O on 2009.04.23 03:37

  • How to assign the default value to search parameter

    Hi Experts,
    I am using search view , In this I have 5 parameter lets say Transaction Type, Partner No. etc... Now I want to assign a default value to transaction type ( lets say TA) . User should be able to see this default value in the transaction type field before pressing search button.
    How can I do it?
    My second problem is: I have configured this search view using configuration tool but I want to assign only one value to transaction type (i.e. user should not be able to add new row in the search criteria for the transaction type by using + sign)  but in rest 4 fields he can add new row and search based on that.
    Note: I am using only "Is" criteria .
    Any pointer will be helpful for me
    Thanks and regards,
    Sandeep

    Hi Sandeep,
    For the default search values, here is a solution. You have to redefine the method GET_VALUE1 of the context node
    For example if it is the BP search (component BP_HEAD_SEARCH) context node is your enhanced class: ZL_BP_HEAD__MAINSEARCH_CN00
    METHOD get_value1.
      CALL METHOD super->get_value1
        EXPORTING
          attribute_path = attribute_path
          iterator       = iterator
        RECEIVING
          value          = value.
      TRY.
    *     Delegate operation to selection parameter
          DATA: current TYPE REF TO if_bol_bo_property_access.
          IF iterator IS BOUND.
            current = iterator->get_current( ).
          ELSE.
            current = me->parameter_collection->get_current( ).
          ENDIF.
          IF current->get_property_as_string( iv_attr_name = 'ATTR_NAME' ) EQ 'XXX'.
            IF value IS INITIAL.
              value = 'Your default value'.
            ENDIF.
          ENDIF.
        CATCH cx_root.
      ENDTRY.
    ENDMETHOD.
    where XXX is the name of the field.
    Default value will then appear in your search field, but you are still able to modify it if you want...
    Regards,
    Fabian

  • Assigning LOV return Value to multiple text items

    Hi all
    I have a custom form on which i have 10 text items
    text item 1,text item 2 ....text item10
    I have a table xx_querywith fields
    text_item,query
    i have inserted into the xx_query table
    insert into xx_query(text_item,query)
    values(text_item1,'select sysdate from dual');
    insert into xx_query(text_item,query)
    values(text_item2,'select sysdate-1 from dual');
    I have created a record group dynamically and i am getting the query from the query column of the xx_query table into the record group(say test_rg)
    I have created a LOV test_lov and thr set_lov_property i have populated the test_rg query into the test_LOV
    is it possible for me to set the return item of the LOV dynamically so that i can get the LOV on the item which i want to ?
    thanks
    _

    Hi All
    thanks for your responses
    I have Created a control item and assigned the return value of the LOV to the control item
    and i have assigned the LOV to the text item that i want
    Currently when i navigate to the text item the LOV is visible
    but when i select a value from the LOV the value is not getting populated into the text item
    I have assigned the value of the control item to the text item
    but i am not sure in which trigger to write the code so as when i select the value from the LOV the value should be shown on the form populating in the text item
    Thanks

  • A question about assigning a default value

    Hi guys, I have a question about assigning a default value to a Numeric Decision CO. This Co needs 2 parameters to compare with each other. I wanna assign para1 during runtime and para2 during design time, but I have no idea how to assign a default value to para2 during design time. Can anyone help me solve this question? Thx a lot.
    BTW I`m searching an article about Time-off example`s "details". I have read several articles about time-off example, but those are not detailed enough. I wanna know about all details of COs. Can anyone forward such article to me, plz.  Thx again.^^

    Hi,
    You can assign a default value to the parameter of a callable object.
    First attach your CO to an Action.At the action level you can assign default values to the CO Parameters.
    Select the action in the design time.
    Select the parameters tab for that action.
    Select the required paramter. At the top, you can find Default value tab, with that you can assign default value.
    I think you can achieve your requirements with Business logic CO better.
    [Business Logic CO|http://help.sap.com/saphelp_nwce10/helpdata/en/44/3d3936c5c14a8fe10000000a1553f6/content.htm]
    Thanks

Maybe you are looking for

  • Error while coming out of MM06 without making any change.

    Hi I am trying to check-uncheck some flags for material deletion in transaction MM06 through LSMW. I am using the Batch Input recording method. When i am making any sort of change to the material it works fine. But when there is a material whose flag

  • Oracle 8.0.5 Post Installation Problem

    Hi all, I have installed Oracle 8.0.5.1 is installed on my RH 6.0 box. However, I am running into a couple of post-installation problems. 1. root.sh (sucessfully ran). 2. glibc patch (successfuly ran). There were a few errors on the screen with the "

  • Logical and Physical Standby on same Node

    Is it possible to have a logical and physical standby database for a primary database on the same node (i.e. primary on NodeA, logical and physical database of primary on NodeB)? Will there be any conflicts with data guard broker with this configurat

  • Can't drag icons out of my dock

    I can't drag files out of stacks (Downloads or Application folders) or app icons off my dock. I reset my SMC when I rebooted and it worked but then I reboot the next day (today) and it won't work anymore. Do I really have to reset SMC every time I bo

  • Keeps opening several home pages when I click on 'home'

    Everytime I click on the home page (I use Google) itcreates at least 3 homepage tabs. By the end of the day I can have 20 or more tabs.