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

i have following url and wants to write programme in java GUI - redButton:JButto

ID: 3886214 • Letter: I

Question

i have following url and wants to write programme in java GUI

- redButton:JButton

- greenButton:Button

-YellowButton:Button

-buttonLabel:JLabel

- lastpressedLabel:JLabel

-buttonPanel:JPanel

+ TrafficLightPanel()

TrafficLightPanel extends JPanel

- redButton:JButton

- greenButton:Button

-YellowButton:Button

-buttonLabel:JLabel

- lastpressedLabel:JLabel

-buttonPanel:JPanel

+ TrafficLightPanel()

ButtonListener implements ActionListener + actionPerformed(e:ActionEvent):void LIghtPAnel extends JPanel + paintComponent(g:Graphics):void

Explanation / Answer

May be what you are looking for a structure code , please find it below. If you have some specific code requirements to be performed inside the button listener and other methods that you didn't mention here, please try to complete that gap yourself.

import javax.swing.JPanel;

import javax.swing.JButton;

import java.awt.Graphics;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import javax.swing.JLabel;

public class TrafficLightPanel extends JPanel {

/**

* Create the panel.

*/

public TrafficLightPanel() {

JButton redButton = new JButton("Red button");

add(redButton);

JButton YellowButton = new JButton("Yellow button");

add(YellowButton);

JButton GreenButton = new JButton("Green button");

add(GreenButton);

JLabel buttonLabel = new JLabel("button label");

add(buttonLabel);

JLabel lblLastPressedLabel = new JLabel("last pressed label");

add(lblLastPressedLabel);

JPanel buttonPanel = new JPanel();

add(buttonPanel);

redButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

}

});

class ButtonListener implements ActionListener

{

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

}

}

class LightPAnel extends JPanel

{

public void paintComponent(Graphics g)

{

}

}

}

}