/* 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 javax.swing.*; 

2. import java.awt.*; 

3. import java.awt.event.*; 

4.  

5. public class Adapt2Sw 

6.     extends JApplet 

7.

8.   Color col = Color.yellow ; 

9.   JPanel cp ; 

10.  

11.   class MMA extends MouseMotionAdapter 

12.   { 

13.     public void mouseDragged ( MouseEvent   ev  ) 

14.     { 

15.       int c = ev.getX(); 

16.       if ( c < 0 ) c = 0

17.       if ( c > 255 ) c = 255

18.  

19.       col = new Color ( 0, 0, c ) ; 

20.       cp.setBackground ( col ) ; 

21.     } 

22.   } ///end inner class MMA 

23.  

24.   public Adapt2Sw () 

25.   { 

26.     cp =  new Content() ; 

27.      setContentPane( cp ); 

28.   } 

29.   class Content 

30.     extends JPanel 

31.   { 

32.     Content() 

33.     { 

34.       addMouseMotionListener ( new MMA() ) ; 

35.     } 

36.   } //end Content 

37.

38.