/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. import java.awt.*; 

2. import java.awt.event.*; 

3. import java.applet.*; 

4.  

5. public class Instant 

6.     extends Applet 

7.     implements ActionListener 

8.

9.   int  randomnumber = 77787877

10.  

11.   Button   bt1, bt2 ; 

12.   TextArea   ta1, ta2 ; 

13.  

14.   public void 

15.   actionPerformed ( ActionEvent ev ) 

16.   { 

17.     double  rnd =  Math.random() * Integer.MAX_VALUE

18.     randomnumber = (int) rnd  ; 

19.  

20.     if  ( ev.getSource() == bt1  ) 

21.       ta1.append ( randomnumber   +  "\n" ) ; 

22.     else 

23.       ta2.append ( randomnumber   +  "\n" ) ; 

24.  

25.     Color  col = new Color ( randomnumber ) ; 

26.     setBackground ( col ) ; 

27.   } 

28.  

29.   public Instant (  ) 

30.   { 

31.     bt1 = new Button ( "Find your favorite color" ) ; 

32.  

33.     bt2 = new Button ( "Me too, me too" ) ; 

34.     bt2.setForeground ( Color.blue ) ; 

35.     bt2.setBackground ( Color.yellow ) ; 

36.  

37.     ta1 = new TextArea ( 5, 20 ) ; 

38.     ta2 = new TextArea ( 3, 30 ) ; 

39.     ta1.setBackground ( Color.white ) ; 

40.     ta2.setBackground ( Color.yellow ) ; 

41.     ta2.setForeground ( Color.red ) ; 

42.   } 

43.  

44.   public void init ( ) 

45.   { 

46.     add ( bt1 ) ; 

47.     add ( bt2 ) ; 

48.     bt1.addActionListener ( this ); 

49.     bt2.addActionListener ( this ); 

50.     add ( ta1 ) ; 

51.     add ( ta2 ) ; 

52.     ta1.append ( randomnumber +  "\n" ) ; 

53.     ta2.append ( randomnumber +  "\n" ) ; 

54.  

55.     Color  col = new Color ( randomnumber ) ; 

56.     setBackground ( col ) ; 

57.      

58.     validate (); 

59.   } 

60.

61.