import java.awt.*; import javax.swing.*; import java.awt.event.*; class Funny extends JComponent implements WindowListener { private boolean foreground; public Funny() { super(); foreground = true; } public void windowClosed(WindowEvent evenement) {} public void windowClosing(WindowEvent evenement) {} public void windowDeiconified(WindowEvent evenement) {} public void windowIconified(WindowEvent evenement) {} public void windowOpened(WindowEvent evenement) {} public void windowActivated(WindowEvent evt) { foreground = true; repaint(); } public void windowDeactivated(WindowEvent evt) { foreground = false; repaint(); } @Override protected void paintComponent(Graphics brush) { Graphics newBrush = brush.create(); if (this.isOpaque()) { newBrush.setColor(this.getBackground()); newBrush.fillRect(0, 0, this.getWidth(), this.getHeight()); } newBrush.setColor(Color.GREEN); newBrush.fillRect(0, 0, getWidth(), getHeight()); if (foreground) { newBrush.setColor(Color.MAGENTA); newBrush.fillOval(0, 0, getWidth(), getHeight()); } else { newBrush.setColor(Color.CYAN); int[] x1 = {0, getWidth(), getWidth() / 2}; int[] y1 = {0, 0, getHeight() / 2}; int[] x2 = {0, getWidth(), getWidth() / 2}; int[] y2 = {getHeight(), getHeight(), getHeight() / 2}; newBrush.fillPolygon(x1, y1, 3); newBrush.fillPolygon(x2, y2, 3); } } } public class Attente { public static void main(String[] args) { JFrame f = new JFrame("Attente"); f.setSize(200, 200); f.setLocation(100, 100); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(null); Funny n = new Funny(); n.setSize(f.getWidth(), f.getHeight()); n.setLocation(0, 0); f.add(n); f.addWindowListener(n); f.setVisible(true); } }