/* 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. ======  ApComUno.java   ========== 

2. import javax.swing.* ; 

3. import java.applet.* ; 

4. import java.awt.* ; 

5. import java.awt.event.*; 

6.  

7. public class ApComuno 

8.     extends JApplet implements ActionListener 

9.

10.   JButton btn ; 

11.   JLabel lbl ; 

12.   boolean which = true

13.   Container cp ; 

14.  

15.   public void actionPerformed( ActionEvent ev ) 

16.   { 

17.     AppletContext ac = getAppletContext() ; 

18.     Applet apl = ac.getApplet( "due" ) ; 

19.     if ( apl == null

20.       return

21.     if ( !( apl instanceof ApComdue ) ) 

22.       return

23.     ApComdue otherap =  (ApComdue) apl ; 

24.  

25.     otherap.performRequest() ; 

26.   } 

27.  

28.   public void performRequest () 

29.   { 

30.     which = ! which ; 

31.     if ( which ) 

32.       cp.setBackground ( Color.yellow ) ; 

33.     else 

34.       cp.setBackground ( Color.lightGray ) ; 

35.   } 

36.  

37.   public ApComuno ( ) 

38.   { 

39.     lbl = new JLabel ( "Let due change its color" )  ; 

40.     btn = new JButton ( "By clicking here" ) ; 

41.   } 

42.  

43.   public void init() 

44.   { 

45.     cp = getContentPane(); 

46.     cp.setBackground ( Color.pink ) ; 

47.     btn.addActionListener ( this ) ; 

48.     cp.setLayout( new FlowLayout() ); 

49.     cp.add ( lbl ) ; 

50.     cp.add ( btn ) ; 

51.   } 

52.

53. =====  apcom.html  ============= 

54. <APPLET 

55.   NAME    = "uno" 

56.   CODE     = "ApComuno.class" 

57.   WIDTH    = "400" 

58.   HEIGHT   = "200" 

59.

60. </APPLET

61. ...... 

62. <APPLET 

63.   NAME    = "due" 

64.   CODE     = "ApComdue.class" 

65.   WIDTH    = "300" 

66.   HEIGHT   = "300" 

67.

68. </APPLET

69. ======== ApComdue.java ============ 

70. import javax.swing.* ; 

71. import java.awt.* ; 

72. import java.applet.* ; 

73. import java.awt.event.*; 

74.  

75. public class ApComdue 

76.     extends JApplet implements ActionListener 

77.

78.   JButton btn ; 

79.   JLabel lbl ; 

80.   boolean which = true

81.   Container cp ; 

82.  

83.   public void actionPerformed( ActionEvent ev ) 

84.   { 

85.      AppletContext ac = getAppletContext() ; 

86.      Applet apl = ac.getApplet( "uno" ) ; 

87.      if ( apl == null

88.       return

89.      if ( !( apl instanceof ApComuno ) ) 

90.       return

91.      ApComuno otherap =  (ApComuno) apl ; 

92.  

93.      otherap.performRequest() ; 

94.   } 

95.  

96.   public void performRequest () 

97.   { 

98.      which = ! which ; 

99.      if ( which ) 

100.       cp.setBackground ( Color.green ) ; 

101.      else 

102.       cp.setBackground ( Color.cyan ) ; 

103.   } 

104.  

105.   public ApComdue ( ) 

106.   { 

107.      lbl = new JLabel ( "Let applet uno change its color" )  ; 

108.      btn =  new JButton ( "Press or click" ) ; 

109.   } 

110.  

111.   public void init() 

112.   { 

113.     cp = getContentPane(); 

114.     cp.setBackground ( Color.orange ) ; 

115.     cp.setLayout( new FlowLayout() ); 

116.     cp.add ( lbl ) ; 

117.     btn.addActionListener ( this ) ; 

118.     cp.add ( btn ) ; 

119.   } 

120.