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

4. public class Images1 

5.     extends JApplet 

6.

7.   Image img, img2 ; 

8.   ImageContent cp ; 

9.  

10.   public Images1() 

11.   { 

12.     cp = new ImageContent() ; 

13.     setContentPane( cp ) ; 

14.   } 

15.   public void init() 

16.   { 

17.     img = getImage (  getCodeBase(), "trans.gif"  ); 

18.  

19.     cp.ta.append ( "init:\t" +  img.getHeight(this) + "\n" ); 

20.  

21.     img2 = getImage (  getCodeBase(), "chopin.jpg"  ); 

22.   } 

23. //==== inner class : ================ 

24.   class ImageContent 

25.     extends JPanel 

26.   { 

27.   int cnt = 1

28.  

29.   JTextArea ta ; 

30.   JScrollPane sp ; 

31.  

32.   public void paintComponent ( Graphics gr ) 

33.   { 

34.     super.paintComponent( gr ); 

35.  

36.     ta.append ( "paint: " + (cnt++) + "\t" 

37.          + img.getHeight(null) + "\n" ); 

38.  

39.     gr.drawImage ( img, 150, 150

40.       img.getWidth(null), img.getHeight(null), null ); 

41.  

42.     gr.drawImage ( img, 10,20, 75,75, null ); 

43.  

44.     gr.drawImage ( img2, 5, 160

45.       img2.getWidth(null), img2.getHeight(null

46.         , Images1.this  ); 

47.   } 

48.    

49.   public ImageContent() 

50.   { 

51.     ta = new JTextArea ( 7, 20 ) ; 

52.     sp = new JScrollPane ( ta ); 

53.     add ( sp ); 

54.   } 

55.  } 

56. //=====end inner class ============= 

57.

58. /*==== other source : ============== 

59. Toolkit.getDefaultToolkit().getImage(...) 

60. */