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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:26:03+00:00 2026-05-29T19:26:03+00:00

I am getting an error: constructor RedListener in class RedListener cannot be applied to

  • 0

I am getting an error: constructor RedListener in class RedListener cannot be applied to given types;
jrbRed.addActionListener(new RedListener(canvas, canvas2));

I am getting one for each of the listeners. The program is supposed to be a traffic light that when I click on a radio button that light “lights” up. if its not clicked then its just supposed to be outlined in the color

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;



public class Lab4Frame extends JFrame {
    //public boolean red, yellow, green;
    Lab4Frame(){
        this.setLayout(new BorderLayout());
        setTitle("Lab 4 - Application #1");
        Lab4Panel p = new Lab4Panel();
        Lab4RadioButtonPanel p2 = new Lab4RadioButtonPanel();
        add(p, BorderLayout.CENTER);
        add(p2, BorderLayout.SOUTH);
    }

    public static void main(String[] args){

            Lab4Frame frame = new Lab4Frame();
            frame.setTitle("Lab4 Application # 1");
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(600, 600);
            frame.setVisible(true);
    }

}

class Lab4RadioButtonPanel extends JPanel {
        Lab4Panel canvas = new Lab4Panel();
        Lab4RadioButtonPanel canvas2 = new Lab4RadioButtonPanel();
    public Lab4RadioButtonPanel() {
        boolean red, green, yellow;



        this.setLayout(new FlowLayout());
        JRadioButton jrbRed = new JRadioButton("Red", true);
        JRadioButton jrbYellow = new JRadioButton("Yellow");
        JRadioButton jrbGreen = new JRadioButton("Green");

        this.setBorder(BorderFactory.createLineBorder(Color.black));

        ButtonGroup group = new ButtonGroup();
        group.add(jrbRed);
        group.add(jrbYellow);
        group.add(jrbGreen);

        this.add(jrbRed);
        this.add(jrbYellow);
        this.add(jrbGreen);

        jrbRed.addActionListener(new RedListener(canvas, canvas2));
        jrbYellow.addActionListener(new YellowListener(canvas, canvas2));
        jrbGreen.addActionListener(new GreenListener(canvas, canvas2));

    }
}










class Lab4Panel extends JPanel{


    public Lab4Panel(){}



    boolean red, green, yellow;
    int radius = 5;
    int x = -1;
    int y = -1;

    public void setRed(){
        red = true;
        repaint();
    }

    protected void paintComponent(Graphics g){
        if (x<0 || y<0) {
            x = getWidth() / 2 - radius;
            y = getHeight() / 2 - radius;
        }
        super.paintComponent(g);
        g.drawRect(x - 10,y - 90, 40, 120);
        g.drawOval(x,y - 80, 4 * radius, 4 * radius);
        g.drawOval(x,y - 40, 4 * radius, 4 * radius);
        g.drawOval(x,y, 4 * radius, 4 * radius);
        g.drawRect(x - 5,y - 90, 40, 120);

        if(red){
            g.setColor(Color.RED);
            g.fillOval(x,y - 80, 4 * radius, 4 * radius);
            repaint();
        }

        else if (yellow){
            g.setColor(Color.YELLOW);
            g.fillOval(x,y - 40, 4 * radius, 4 * radius);
            repaint();
        }

        if(green){
            g.setColor(Color.GREEN);
            g.fillOval(x,y, 4 * radius, 4 * radius);
            repaint();
        }

    }


}


class RedListener implements ActionListener{
    private Lab4RadioButtonPanel canvas;
    private Lab4Panel canvas2;

    RedListener(Lab4RadioButtonPanel canvas, Lab4Panel canvas2) {
     this.canvas = canvas;
    }

    public void actionPerformed(ActionEvent e){
        canvas2.setRed();
    }
}

class YellowListener implements ActionListener{
    private Lab4RadioButtonPanel canvas;
    private Lab4Panel canvas2;

    YellowListener(Lab4RadioButtonPanel canvas, Lab4Panel canvas2) {
     this.canvas = canvas;
    }

    public void actionPerformed(ActionEvent e){
        canvas2.setRed();
    }
}

class GreenListener implements ActionListener{
    private Lab4RadioButtonPanel canvas;
    private Lab4Panel canvas2;

    GreenListener(Lab4RadioButtonPanel canvas, Lab4Panel canvas2) {
     this.canvas = canvas;
    }

    public void actionPerformed(ActionEvent e){
        canvas2.setRed();
    }
}
  • 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-05-29T19:26:06+00:00Added an answer on May 29, 2026 at 7:26 pm

    You have this:

    Lab4Panel canvas = new Lab4Panel();
    Lab4RadioButtonPanel canvas2 = new Lab4RadioButtonPanel();
    

    and this:

    jrbRed.addActionListener(new RedListener(canvas, canvas2));
    

    but your constructor is this:

    RedListener(Lab4RadioButtonPanel canvas, Lab4Panel canvas2)
    

    You probably want:

    jrbRed.addActionListener(new RedListener(canvas2, canvas));
    

    i.e. you reversed the order of parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the following error: The constructor Intent(new View.OnClickListener(){}, Class<DrinksTwitter>) is undefined In
I am getting this error: symbol : constructor JTable(float[][],java.lang.String[]) location: class javax.swing.JTable table =
I am getting a compile error, saying that the copy constructor of the scoped_ptr
hi im new to c# and was trying to code but getting error can
Please consider my codes below: I'm getting an error Constructor on type 'System.String' not
While mapping class i am getting error 'T' must be a non-abstract type with
Java is complaining! cannot find symbol symbol : constructor Bar() location: class Bar JPanel
I am always getting the error No parameterless constructor defined for this object. when
I am getting an error in *insert_nodes function: error: expected constructor, destructor, or type
I am getting error ERROR/AndroidRuntime(1482): java.lang.NullPointerException from my ImageAdapter class.Please Help me to solve

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.