Results 1 to 3 of 3
  1. #1
    Lehane_9 is offline Member
    Join Date
    Dec 2007
    Posts
    6
    Rep Power
    0

    Default get numeric value from a text field

    private int amount;
    private amountTxt;

    amountTxt = new JTextField(1);
    c.add(amountTxt);

    amount = amountTxt.getText();// i need the to use the value of amount below (price * amount)

    JOptionPane.showMessageDialog(null, "Ticket price: "+(price*amount)+".00"

    Help would be appreciated thanks.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    amount = Integer.parseInt(amountTxt.getText());

  3. #3
    ferranb is offline Member
    Join Date
    Jun 2008
    Posts
    22
    Rep Power
    0

    Default

    Notice that the euros are not integer. You can use Float.parseFloat() (or Decimal...) instead.

Similar Threads

  1. Replies: 2
    Last Post: 04-16-2008, 01:18 PM
  2. Allowing only numeric values in a TextField
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-01-2008, 11:08 PM
  3. Waste Space & Text Field
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 2
    Last Post: 12-01-2007, 08:44 AM
  4. Help with define an integer field
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 08:32 AM
  5. Final field question
    By derrickD in forum Advanced Java
    Replies: 1
    Last Post: 04-28-2007, 11:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •