Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7791901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:02:31+00:00 2026-06-01T22:02:31+00:00

The below code is an action listener for a project. Basically, I have 4

  • 0

The below code is an action listener for a project. Basically, I have 4 radio buttons and when I click one, I want it to change a variable on screen. When I run the code, it is simply adding together all the values. Are there any other ways to do this?

class Calc implements ActionListener
    {
     public void actionPerformed(ActionEvent event)
     {
       double base = 0.00;
       double options;
       double total;

      if (Button25.isSelected());
      {
      base = base + 999.99;
      String base2 = Double.toString(base);
      lblBaseAns.setText(base2);
      }

      if (Button32.isSelected());
      {
        base = base + 1049.99;
        String base2 = Double.toString(base);
        lblBaseAns.setText(base2);
      }

      if (Button35.isSelected());
      {
        base = base + 1099.99;
        String base2 = Double.toString(base);
        lblBaseAns.setText(base2);
      }

      if (Button42.isSelected());
      {
        base = base + 1155.99;
        String base2 = Double.toString(base);
        lblBaseAns.setText(base2);
      }


     }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:02:33+00:00Added an answer on June 1, 2026 at 10:02 pm

    The problem is that, for each if() statement, such as if (Button32.isSelected());, you have a ; symbol at the end. This shouldn’t be there. Here is the corrected code…

    class Calc implements ActionListener {
        public void actionPerformed(ActionEvent event){
            double base = 0.00;
            double options;
            double total;
    
            if (Button25.isSelected()){ // changed
                base = base + 999.99;
                String base2 = Double.toString(base);
                lblBaseAns.setText(base2);
            }
            else if (Button32.isSelected()){ // changed
                base = base + 1049.99;
                String base2 = Double.toString(base);
                lblBaseAns.setText(base2);
            }
            else if (Button35.isSelected()){ // changed
                base = base + 1099.99;
                String base2 = Double.toString(base);
                lblBaseAns.setText(base2);
            }
            else if (Button42.isSelected()){ // changed
                base = base + 1155.99;
                String base2 = Double.toString(base);
                lblBaseAns.setText(base2);
            }
        }
    }
    

    As an alternative, why don’t you get the button that was clicked from the ActionEvent, and then use the button in your if-else branch…

    class Calc implements ActionListener {
        public void actionPerformed(ActionEvent event){
            double base = 0.00;
            double options;
            double total;
    
            Object clickedObject = event.getSource();
            if (clickedObject instanceof JRadioButton){
                JRadioButton clickedButton = (JRadioButton)clickedObject;
    
                if (clickedButton == Button25){
                    base = base + 999.99;
                    String base2 = Double.toString(base);
                    lblBaseAns.setText(base2);
                }
                else if (clickedButton == Button32){
                    base = base + 1049.99;
                    String base2 = Double.toString(base);
                    lblBaseAns.setText(base2);
                }
                else if (clickedButton == Button35){
                    base = base + 1099.99;
                    String base2 = Double.toString(base);
                    lblBaseAns.setText(base2);
                }
                else if (clickedButton == Button42){
                    base = base + 1155.99;
                    String base2 = Double.toString(base);
                    lblBaseAns.setText(base2);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have below html code in one of the opensource project. <form action=/wiki/bin/view/Main/Search> <div
In the code below I pass method B as an action to be perfomed
Below code makes form to be submitted without html5 validation... $j(document).on(click, #client_entry_add, function(event){ ajax_submit();});
The below code is very simple. I have a jQuery autocomplete bound to an
I am new to java swing. I have pasted my code below for your
In my code, ontouch listener of a button is fired twice. please find below
I have a datebase lyrics with a table lyrics1, and with the code below
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
below code is my databasehandler class i got it from a tutorial. Beside that
Below code : URL oracle = new URL(http://www.oracle.com/); URLConnection inputStream =oracle.openConnection(); InputStream in =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.