Results 1 to 2 of 2
  1. #1
    Jackie88 is offline Member
    Join Date
    Jul 2014
    Rep Power

    Default Autofill a JTextField once another JTextField has been typed into

    Hi there

    I am trying to get a JTextField to autofill with the result of a calculation made from user input in another JTextField

    I am building a virtual ticket machine, where i want the user to select ticket type, type in the quantity of tickets they would like, and then so as soon as they have clicked out of the quantity textfield, I want the payment required textfield to autofil with the correct cost of the users selection, I have wrote the code to do the calculation for the cost, I just dont know how to put the cost in the payment required textfield at this stage.

    Here is my code for this bit;
    Java Code:
    public void actionPerformed(ActionEvent e) {
            String TypeName = (String)TicketTypeList.getSelectedItem();
            int arrayIndex = Arrays.asList(typeStrings).indexOf(TypeName);
            String quantityStr = noOfTickets.getText();
            Double quantity = Double.parseDouble(quantityStr);
            if (noOfTickets.getText().equals(null) || noOfTickets.getText().equals("")){
                showMessageDialog(null, "Please enter a quantity");
            } else {
                switch (arrayIndex){
                case 0: 
                    amountRequired = 15.00*quantity;
                case 1:
                    amountRequired = 10.20*quantity;
                case 2:
                    amountRequired = 5.70*quantity;
                case 3:
                    amountRequired = 30.85*quantity;

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power

    Default Re: Autofill a JTextField once another JTextField has been typed into

    Sounds like a job for a FocusListener. You could also do it with a DocumentListener or an ActionListener.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. JTextField ???
    By Nhatmeister in forum New To Java
    Replies: 6
    Last Post: 11-23-2013, 07:52 PM
  2. Replies: 3
    Last Post: 11-14-2011, 05:13 AM
  3. Replies: 0
    Last Post: 08-30-2011, 09:18 AM
  4. Replies: 1
    Last Post: 01-30-2009, 06:44 PM
  5. JtextField
    By kashifu in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2008, 04:25 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