1 package sample.duplicate;
2 
3 import java.applet.*;
4 import java.awt.*;
5 import java.awt.event.*;
6 
7 public class Viewer extends Applet
8     implements MouseListener, ActionListener, WindowListener
9 {
10     private static final Color[] colorList = {
11 	Color.orange, Color.pink, Color.green, Color.blue };
12 
13     private Ball ball;
14     private int colorNo;
15 
init()16     public void init() {
17 	colorNo = 0;
18 	Button b = new Button("change");
19 	b.addActionListener(this);
20 	add(b);
21 
22 	addMouseListener(this);
23     }
24 
start()25     public void start() {
26 	ball = new Ball(50, 50);
27 	ball.changeColor(colorList[0]);
28     }
29 
paint(Graphics g)30     public void paint(Graphics g) {
31 	ball.paint(g);
32     }
33 
mouseClicked(MouseEvent ev)34     public void mouseClicked(MouseEvent ev) {
35 	ball.move(ev.getX(), ev.getY());
36 	repaint();
37     }
38 
mouseEntered(MouseEvent ev)39     public void mouseEntered(MouseEvent ev) {}
40 
mouseExited(MouseEvent ev)41     public void mouseExited(MouseEvent ev) {}
42 
mousePressed(MouseEvent ev)43     public void mousePressed(MouseEvent ev) {}
44 
mouseReleased(MouseEvent ev)45     public void mouseReleased(MouseEvent ev) {}
46 
actionPerformed(ActionEvent e)47     public void actionPerformed(ActionEvent e) {
48 	ball.changeColor(colorList[++colorNo % colorList.length]);
49 	repaint();
50     }
51 
windowOpened(WindowEvent e)52     public void windowOpened(WindowEvent e) {}
53 
windowClosing(WindowEvent e)54     public void windowClosing(WindowEvent e) {
55 	System.exit(0);
56     }
57 
windowClosed(WindowEvent e)58     public void windowClosed(WindowEvent e) {}
59 
windowIconified(WindowEvent e)60     public void windowIconified(WindowEvent e) {}
61 
windowDeiconified(WindowEvent e)62     public void windowDeiconified(WindowEvent e) {}
63 
windowActivated(WindowEvent e)64     public void windowActivated(WindowEvent e) {}
65 
windowDeactivated(WindowEvent e)66     public void windowDeactivated(WindowEvent e) {}
67 
main(String[] args)68     public static void main(String[] args) {
69 	Frame f = new Frame("Viewer");
70 	Viewer view = new Viewer();
71 	f.addWindowListener(view);
72 	f.add(view);
73 	f.setSize(300, 300);
74 	view.init();
75 	view.start();
76 	f.setVisible(true);
77     }
78 }
79