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 8144051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:16:07+00:00 2026-06-06T13:16:07+00:00

For my application, I created two JRadioButton grouped into a selection ButtonGroup . I

  • 0

For my application, I created two JRadioButton grouped into a “selection” ButtonGroup. I added an ActionListener called “SelectionListener.” When I check if my RadioButton is selected using isSelected(), it appears that my selection is not getting passed over to the ActionListener.

public static void main(String[] args) {
    JRadioButton monthlyRadioButton = new JRadioButton("Monthly Payment", true);
    JRadioButton loanAmountButton = new JRadioButton("Loan Amount");
    ButtonGroup selection = new ButtonGroup();
    selection.add(monthlyRadioButton);
    selection.add(loanAmountButton);
    monthlyRadioButton.addActionListener(new SelectionListener());
    loanAmountButton.addActionListener(new SelectionListener());
} 

SelectionListener.java

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class SelectionListener implements ActionListener {
    public void actionPerformed(ActionEvent event){
      if(event.getSource() == monthlyRadioButton)
        System.out.println("You clicked Monthly");
      else
        System.out.println("You clicked Loan Amount");

    }
}

The parameters monthlyRadioButton is not getting passed over to my SelectionListener class. I’m getting an error that it is not being resolved.

How do I pass the monthlyRadioButton in my main method over to my SelectionListener class?

  • 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-06T13:16:09+00:00Added an answer on June 6, 2026 at 1:16 pm

    You car retrieve the sender of the event is being handled.

    Something like:

    class SelectionListener implements ActionListener {
        private JComponent monthlyRadioButton;
        private JComponent loanAmountButton;
    
        public SelectionListener(JComponent monthlyRadioButton, JComponent loanAmountButton) {
            this.monthlyRadioButton = monthlyRadioButton;
            this.loanAmountButton = loanAmountButton;
        }
    
        public void actionPerformed(ActionEvent event){
            if(event.getSource() == monthlyRadioButton)
                System.out.println("You clicked Monthly");
            else if(event.getSource() == loanAmountButton)
                System.out.println("You clicked Loan Amount");
        }
    }
    

    On your main method you could instantiate it like:

        monthlyRadioButton.addActionListener(new SelectionListener(monthlyRadioButton, loanAmountButton));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created two forms in my Windows Application. One Form acts as a
I have created two DbContexts, one is for application configuration, the second is for
i am new to iPad developer, i have created two or three iPad application
I created two application MainApps and SubApps, the SubApps has a modal type dialogbox
I created two Spinners to display the data in my application. In my first
I have created two dictionaries in the user defaults of my application to represent
I have two different versions (Basic and Professional) of my application. I have created
i am new to iPad developer, i have created two or three iPad application
i am new to iPad developer, i have created two or three iPad application
I have created two layout files (in res/layout and res/layout-land) for my application. But

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.