import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.BorderLayout;

class TrafficLight {
  String state;
  public TrafficLight(String state) {
    this.state = state;
  }
  public void next() {
    if(this.state.equals("red")) { this.state = "green"; }
    else if(this.state.equals("yellow")) { this.state = "red"; }
    else { this.state = "yellow"; }
  }
}

class TrafficLightDrawing extends JPanel {
  TrafficLight tl;
  public TrafficLightDrawing(TrafficLight tl) {
    this.tl = tl;
  }
  // ... fields later ...

  public void paintComponent(Graphics g) {
    // Fill in this method to draw three circles
    // Draw the current state of tl in color, and others in gray
    Color colorTop = Color.GRAY;
    Color colorMiddle = Color.GRAY;
    Color colorBottom = Color.GRAY;

    if(this.tl.state.equals("red")) { colorTop = Color.RED; }
    if(this.tl.state.equals("yellow")) { colorMiddle = Color.YELLOW; }
    if(this.tl.state.equals("green")) { colorBottom = Color.GREEN; }

    g.setColor(colorTop);
    g.fillOval(200, 20, 100, 100);

    g.setColor(colorMiddle);
    g.fillOval(200, 140, 100, 100);

    g.setColor(colorBottom);
    g.fillOval(200, 260, 100, 100);

  }
}

public class GUI {
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    TrafficLight tl = new TrafficLight("green");
    TrafficLightDrawing tld = new TrafficLightDrawing(tl);
    JButton button = new JButton("Advance Light");

    frame.setMinimumSize(new Dimension(600, 400));

    // LayoutManager
    frame.add(button, BorderLayout.PAGE_START);
    frame.add(tld, BorderLayout.CENTER);

    frame.setVisible(true);
  }
}
