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):voidExplanation / 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)
{
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.