Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi i wriiten this program but compiling time it shows few errors can any one fix

ID: 3886123 • Letter: H

Question

Hi i wriiten this program but compiling time it shows few errors can any one fix it for me.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TrafficLightPanel extends Jpanel{
private JButton redButton;
private JButton greenButton;
private JButton amberButton;
private JLable buttonLable;
private JLable lastPressendLabel;
private JLable buttonPanel;
//Constructor set up the GUI

public TrafficLightPanel(){
    red = new JButton("red");
    green = new JButton("green");
    amber = new JButton("amber");
    ButtonListener listener = new ButtonListener();
    red.addActionListener(listener);
    green.addActionListener(listener);
    amber.addActionListener(listener);
  
    buttonLable = new JLable("push a Button");
  
    setTrafficLightPAnelSize(new Dimension(200,300));
    setBackground(Color.Blue);
    setButtonPanelSize(new Dimension(80,290));
    setButtonPanelBackground(Color.White);
    add (buttonLabel);
    add(buttonPanel);
                   
                     
  
                     
}

}
  
  
  

Explanation / Answer

Hi,

I have fixed the compiletime issue. Highlighted the code chnages below.

TrafficLightPanel.java

import java.awt.Color;

import java.awt.Dimension;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JLabel;

import javax.swing.JPanel;

public class TrafficLightPanel extends JPanel{

private JButton redButton;

private JButton greenButton;

private JButton amberButton;

private JLabel buttonLable;

private JLabel lastPressendLabel;

private JLabel buttonPanel;

//Constructor set up the GUI

public TrafficLightPanel(){

redButton = new JButton("red");

greenButton = new JButton("green");

amberButton = new JButton("amber");

ButtonListener listener = new ButtonListener();

redButton.addActionListener(listener);

greenButton.addActionListener(listener);

amberButton.addActionListener(listener);

  

buttonLable = new JLabel("push a Button");

  

setSize(new Dimension(200,300));

setBackground(Color.BLUE);

//setButtonPanelSize(new Dimension(80,290));

//setButtonPanelBackground(Color.White);

add (buttonLable);

//add(buttonPanel);

setVisible(true);   

  

}

public static void main(String a[]) {

new TrafficLightPanel();

}

}

class ButtonListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

}

}

  

  

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote