importjavax.swing.*;importjava.awt.*;classTrafficLightextendsJFrame{privateJRadioButton redBtn, greenBtn, yellowBtn;privateJPanel lightPanel, btnPanel;publicTrafficLight(){// Frame Configssuper("Adi's Traffic");setDefaultCloseOperation(EXIT_ON_CLOSE);setSize(300,400);setResizable(false);setLayout(newBorderLayout());// Creating the buttons redBtn =newJRadioButton("Red"); greenBtn =newJRadioButton("Green"); yellowBtn =newJRadioButton("Yellow");// Make the traffic light to repaint on btn clicks redBtn.addActionListener(e -> lightPanel.repaint()); greenBtn.addActionListener(e -> lightPanel.repaint()); yellowBtn.addActionListener(e -> lightPanel.repaint());// Adding button to a group so that only one can be selected at a timeButtonGroup group =newButtonGroup(); group.add(redBtn); group.add(greenBtn); group.add(yellowBtn);// Creating a panel for buttons btnPanel =newJPanel(newGridLayout(1,3)); btnPanel.add(redBtn); btnPanel.add(greenBtn); btnPanel.add(yellowBtn);// Createing a panel for light lightPanel =newJPanel(){@OverrideprotectedvoidpaintComponent(Graphics g){super.paintComponent(g); g.setColor(Color.BLACK); g.fillRect(100,50,100,200); g.setColor(redBtn.isSelected()?Color.RED :Color.DARK_GRAY); g.fillOval(125,65,50,50); g.setColor(greenBtn.isSelected()?Color.GREEN :Color.DARK_GRAY); g.fillOval(125,125,50,50); g.setColor(yellowBtn.isSelected()?Color.YELLOW :Color.DARK_GRAY); g.fillOval(125,185,50,50);}};// Add btnPanel and lightPanel to the frameadd(btnPanel,BorderLayout.NORTH);add(lightPanel,BorderLayout.CENTER);}publicstaticvoidmain(String[] args){SwingUtilities.invokeLater(()->{TrafficLight frame =newTrafficLight(); frame.setVisible(true);});}}