Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: GUI, textarea help, line by line string

  1. #1
    Member
    Join Date
    Jul 2013
    Location
    Baltimore, MD
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default GUI, textarea help, line by line string

    how can I show multiple lines on gui textField, right now it will only show the latest "value". Please click on the link below to see the GUI output. Notice it's only showing the 2 $1.

    https://drive.google.com/file/d/0B2-...it?usp=sharing

    GUI Code

        private void paymentTextFieldActionPerformed(java.awt.event.ActionEvent evt) {                                                 
     
            double payment = Double.parseDouble(paymentTextField.getText());
            paymentTextField.setText(fmt.format(payment));
     
            finalChange = payment - allTotal;
            change.setText(String.valueOf(fmt.format(finalChange)));
     
            int dollar;
            double cent;
            dollar = (int)finalChange % 1000000;
            cent = finalChange - dollar;
     
            if((dollar / 100) >= 1)
            {
                changeTextArea.setText(dollar / 100 + " $100");
                dollar = dollar - 100 * (dollar / 100);
            }
     
            if((dollar / 50) >= 1)
            {
                changeTextArea.setText(dollar / 50 + " $50");
                dollar = dollar - 50 * (dollar / 50);
            }
     
            if((dollar / 20) >= 1)
            {
                changeTextArea.setText(dollar / 20 + " $20");
                dollar = dollar - 20 * (dollar / 20);
            }
     
            if((dollar / 10) >= 1)
            {
                changeTextArea.setText(dollar / 10 + " $10");
                dollar = dollar - 10 * (dollar / 10);
            }
     
            if((dollar / 5) >= 1)
            {
                changeTextArea.setText(dollar / 5 + " $5");
                dollar = dollar - 5 * (dollar / 5);
            }
     
            if((dollar / 1) >= 1)
            {
                changeTextArea.setText(dollar / 1 + " $1");
            }      
     
        }

    test code output, what I want the GUI above to look like

    1 $5
    2 $1
    3 $0.01

    test code

    package correctchange;
     
    public class CorrectChange {
     
        public static void main(String[] args) {          
     
            double change = 7.03;
     
            int dollar;
            double cent;
            dollar = (int)change % 1000000;
            cent = change - dollar;
     
            // dollar calculation
     
            if((dollar / 100) >= 1)
            {
                System.out.println(dollar / 100 + " $100");
                dollar = dollar - 100 * (dollar / 100);
            }
     
            if((dollar / 50) >= 1)
            {
                System.out.println(dollar / 50 + " $50");
                dollar = dollar - 50 * (dollar / 50);
            }
     
            if((dollar / 20) >= 1)
            {
                System.out.println(dollar / 20 + " $20");
                dollar = dollar - 20 * (dollar / 20);
            }
     
            if((dollar / 10) >= 1)
            {
                System.out.println(dollar / 10 + " $10");
                dollar = dollar - 10 * (dollar / 10);
            }
     
            if((dollar / 5) >= 1)
            {
                System.out.println(dollar / 5 + " $5");
                dollar = dollar - 5 * (dollar / 5);
            }
     
            if((dollar / 1) >= 1)
            {
                System.out.println(dollar / 1 + " $1");
            }
     
            // cents calculation        
     
            if((cent / 0.25) >= 1.00)
            {
                System.out.println((int)(cent / 0.25) + " $0.25");
                cent = cent - 0.25 * (cent / 0.25);
            }
     
            if((cent / 0.10) >= 1.00)
            {
                System.out.println((int)(cent / 0.10) + " $0.10");
                cent = cent - 0.10 * (cent / 0.10);
            }
     
            if((cent / 0.05) >= 1.00)
            {
                System.out.println((int)(cent / 0.05) + " $0.05");
                cent = cent - 0.05 * (cent / 0.05);
            }
     
            if((cent / 0.01) >= 1.00)
            {
                System.out.println((int)(cent / 0.01) + " $0.01");
    //            cent = cent - 0.01 * (cent / 0.01);
            }
     
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: GUI, textarea help, line by line string

    how can I show multiple lines on gui textField, right now it will only show the latest
    Read the API doc for the JTextArea class. There are methods to set the text to a String and to append a String to what is there.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jul 2013
    Location
    Baltimore, MD
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default Re: GUI, textarea help, line by line string

    Quote Originally Posted by Norm View Post
    Read the API doc for the JTextArea class. There are methods to set the text to a String and to append a String to what is there.
    Thank you, I'll try that

Similar Threads

  1. Re: Reading a file line by line using the Scanner class
    By rajaveluswamy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 8th, 2013, 03:38 AM
  2. New line in TextArea(clicking on radiobutton)
    By patzxc in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 3rd, 2013, 11:49 AM
  3. Replies: 10
    Last Post: September 16th, 2011, 07:49 PM
  4. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  5. How to Read a file line by line using BufferedReader?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM