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

4. import java.awt.event.MouseEvent

5. import java.awt.event.MouseListener

6.  

7. public class CompMethodsSw 

8.     extends JApplet 

9.     implements MouseListener 

10.

11.   JButton btn ; 

12.   JLabel lbl ; 

13.   JTextField tf ; 

14.   JTextArea ta ; 

15.   JScrollPane sp ; 

16.   Container cp ; 

17.  

18.   public void mouseClicked ( MouseEvent ev ) 

19.   { 

20.     Object src = ev.getSource (); 

21.     Component clickee = (Component)src ; 

22.  

23.     ta.append ( "Font\t" ); 

24.     ta.append ( clickee.getFont () + "\n" ); 

25.     ta.append ( "Background\t" ); 

26.     ta.append ( clickee.getBackground () + "\n" ); 

27.     ta.append ( "Foreground\t" ); 

28.     ta.append ( clickee.getForeground () + "\n" ); 

29.     ta.append ( "Location\t" ); 

30.     ta.append ( clickee.getLocation () + "\n" ); 

31.     ta.append ( "LocationOnScreen\t" ); 

32.     ta.append ( clickee.getLocationOnScreen () + "\n" ); 

33.     ta.append ( "Size\t" ); 

34.     ta.append ( clickee.getSize () + "\n" ); 

35.     ta.append ( "MinimumSize\t" ); 

36.     ta.append ( clickee.getMinimumSize () + "\n" ); 

37.     ta.append ( "PreferredSize\t" ); 

38.     ta.append ( clickee.getPreferredSize () + "\n" ); 

39.     ta.append ( "Parent\t" ); 

40.     ta.append ( clickee.getParent () + "\n" ); 

41.     ta.append ( "Bounds\t" ); 

42.     ta.append ( clickee.getBounds () + "\n" ); 

43.     ta.append ( "Name\t" ); 

44.     ta.append ( clickee.getName () + "\n" ); 

45.     ta.append ( "Locale\t" ); 

46.     ta.append ( clickee.getLocale () + "\n" ); 

47.     ta.append ( "============================================\n" ); 

48.  

49.   } 

50.  

51.   public CompMethodsSw ( ) 

52.   { 

53.     btn = new JButton ( "The Pressee") ; 

54.     tf = new JTextField ( 20 ); 

55.     lbl = new JLabel ( "Hot gods" ) ; 

56.     ta = new JTextArea ( 20, 40 ) ; 

57.     sp = new JScrollPane ( ta ); 

58.  //   sp.setPreferredSize( new Dimension( 400,400 ) ); 

59.   } 

60.  

61.   public void init() 

62.   { 

63.     cp = getContentPane(); 

64.     cp.setBackground ( Color.yellow ) ; 

65.     lbl.setBackground ( Color.cyan ) ; 

66.     tf.setBackground ( Color.white ) ; 

67.     ta.setBackground ( Color.white ) ; 

68.  

69.     cp.addMouseListener ( this ) ; 

70.     btn.addMouseListener ( this ) ; 

71.     tf.addMouseListener ( this ) ; 

72.     lbl.addMouseListener ( this ) ; 

73.  

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

75.     cp.add (btn); 

76.     cp.add (tf); 

77.     cp.add (lbl); 

78.     cp.add (sp); 

79.   } 

80.  

81.   public void mousePressed(MouseEvent e) {} 

82.   public void mouseReleased(MouseEvent e) {} 

83.   public void mouseEntered(MouseEvent e) {} 

84.   public void mouseExited(MouseEvent e) {} 

85.