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 2 of 2

Thread: Need help on how to add numbers to jlabel

  1. #1
    Junior Member
    Join Date
    Mar 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help on how to add numbers to jlabel

    So Basically I am creating this pizza program and on one page I have a section where people can choose a list of toppings. Now each topping is 1.50 and as soon as they click a topping a sidebar on my gui would display the price. Now I have 12 toppings radio buttons but the problem arises when I click 2 radio buttons it just displays the price 1.50.

    I just want to know if there's a way to add 1.50 to my jLabel on my sidebar every time I press a topping button and when I deselect a topping it would subtract 1.50 from the jLabel so the price is accurate.

    Here is my code I have done til now

     
    Pepperoni Radio Button
     
    final String LastMoney = ToppingsPriceL.getText(); 
    final double LM = Double.parseDouble (ToppingsPriceL.getText()); 
     
    String PBtn = PepperoniBtn.getText(); 
     
    boolean PepperoniBtn; 
    PepperoniBtn = true;
     
     if (PepperoniBtn) { ToppingsDisplayL.setText(PBtn); 
     
    ToppingsPriceL.setText(Money.format(1.50 + LM)); }
     }
     
     
     
    Green Olive Radio Button
     
     
    final String LastMoney = ToppingsPriceL.getText(); 
    final double LM = Double.parseDouble (ToppingsPriceL.getText()); 
     
    String GObtn = GreenOlivesBtn.getText();
     boolean GreenOlivesBtn;
     
     GreenOlivesBtn=true;
     
     if (GreenOlivesBtn) { 
     
    ToppingsDisplayL.setText(GObtn); ToppingsPriceL.setText(Money.format(1.50 + LM)); }

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

    Default Re: Need help on how to add numbers to jlabel

    when I click 2 radio buttons it just displays the price 1.50
    What should be displayed?

    a way to add 1.50 to my jLabel
    Is the JLabel supposed to display a total amount? Should each new order increment the amount shown?

    The posted code needs formatting to help make it readable. Logically nested statements should be indented.
    Statements should not all start in the first column.

    Also there isn't enough code shown to know what is happening.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to add two numbers in the same row of a file
    By adnan11 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 27th, 2014, 03:37 AM
  2. Need a different way to add Cubed numbers 1-10
    By Dtank123456 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 12th, 2014, 03:02 PM
  3. how to add strings as numbers?
    By Dixxon in forum Java Theory & Questions
    Replies: 7
    Last Post: December 8th, 2013, 04:55 PM
  4. How to add the numbers in the following series?
    By namenamename in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 16th, 2013, 07:23 PM
  5. How to add line numbers in Eclipse
    By Brt93yoda in forum Java JDK & IDE Tutorials
    Replies: 1
    Last Post: January 5th, 2012, 11:30 PM