/* 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 Clip 

6.     extends JApplet 

7.         implements MouseListener 

8.

9.   boolean clipit = true

10.  

11.   Container cp ; 

12.  

13.   class ClipContent 

14.     extends JPanel 

15.   { 

16.     public void 

17.     paintComponent ( Graphics gr ) 

18.     { 

19.       super.paintComponent( gr ); 

20.       if ( clipit ) 

21.       { 

22.         gr.setClip ( 78, 103, 100, 60 ) ; 

23.       } 

24.  

25.       for ( int i = 0 ; i < 256; i++ ) 

26.       { 

27.         gr.setColor ( new Color ( i, 0, 0 ) ); 

28.         gr.drawLine ( 128, 128, i, 255 ) ; 

29.         gr.drawLine ( 128, 128, 255-i, 0 ) ; 

30.         gr.drawLine ( 128, 128, 0, i ) ; 

31.         gr.drawLine ( 128, 128, 255, 255-i ) ; 

32.       } 

33.     } 

34.   } // end class 

35.  

36.   public void mouseClicked ( MouseEvent ev ) 

37.   { 

38.     clipit = !clipit ; 

39.     repaint () ; 

40.   } 

41.  

42.   public void 

43.   init () { 

44.     cp =  new ClipContent() ; 

45.     setContentPane( cp ); 

46.     cp.setBackground ( Color.yellow ) ; 

47.     cp.addMouseListener ( this ) ; 

48.   } 

49.  

50.   public void mousePressed(MouseEvent ev) {} 

51.   public void mouseReleased(MouseEvent ev) {} 

52.   public void mouseEntered(MouseEvent ev) {} 

53.   public void mouseExited(MouseEvent ev) {} 

54.

55.