import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class FlashingPanel {

  public static void main(String args[]) {
    FlashingPanel d = new FlashingPanel();
  }

  public FlashingPanel() {
    JFrame frame = new JFrame();
    MyPanel panel = new MyPanel();

    frame.add(panel);
    frame.pack();
    frame.setVisible(true);

    while (true) {
      SwingUtilities.invokeLater(new backgroundSetter(panel,Color.blue));
      panel.repaint();
      SwingUtilities.invokeLater(new backgroundSetter(panel,Color.black));
      try {Thread.sleep(1000);} catch (InterruptedException e) {}
    }
  }

  private class backgroundSetter implements Runnable {
    public JPanel panel;
    public Color color;
 
    public backgroundSetter(JPanel f, Color c) {
      panel = f;
      color = c;
    }
 
    public void run() {
      panel.setBackground(color);
    }
  }
}

