summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/ChgNextApplet.java
blob: 509836975742f5224163d080d9a0e085818bb8a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* ChgNextApplet.java */

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;

public class ChgNextApplet
extends Applet
{
  private String next;

  public void init()
  {
    next = getParameter("next");
    setBackground(Color.red);
    addMouseListener(
      new MouseAdapter()
      {
        public void mouseClicked(MouseEvent event)
        {
          if (next != null) {
            Applet applet = getAppletContext().getApplet(next);
            if (applet != null) {
              int red   = (int)(Math.random() * 256);
              int green = (int)(Math.random() * 256);
              int blue  = (int)(Math.random() * 256);
              applet.setBackground(new Color(red, green, blue));
              applet.repaint();
            }
          }
        }
      }
    );
  }

  public void paint(Graphics g)
  {
    g.drawString("Change " + next, 5, 20);
  }
}