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

6.     extends JApplet 

7.     implements ActionListener 

8.

9.   JLabel lbl ; 

10.   JTextField tf ; 

11.   JButton bt ; 

12.   JPanel pl ; 

13.   JComboBox cb ; 

14.   JSlider sl ; 

15.  

16.  

17.   int nr = 0

18.   public void actionPerformed ( ActionEvent ev ) 

19.   { 

20.     try

21.     String str ; 

22.     switch ( nr ) 

23.     { 

24.     case 0

25.       str = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"

26.       lbl.setText ( str ) ; 

27.  

28.       UIManager.setLookAndFeel ( str ); 

29.       break

30.     case 1

31.       str = UIManager.getCrossPlatformLookAndFeelClassName ( ); 

32.       lbl.setText ( "CROSSPL=Java=Metal=default: " + str ) ; 

33.  

34.       UIManager.setLookAndFeel ( str ) ; 

35.       break

36.     case 2

37.       str = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"

38.       lbl.setText ( str ) ; 

39.  

40.       UIManager.setLookAndFeel ( str ); 

41.       break

42.     case 3

43.       str = UIManager.getSystemLookAndFeelClassName ( ) ; 

44.       lbl.setText ( "Station : " +  str ) ; 

45.  

46.       UIManager.setLookAndFeel ( str ); 

47.       break

48.     } 

49.      SwingUtilities.updateComponentTreeUI ( this ); 

50.  

51.     } 

52.     catch ( Exception ex ) 

53.     { 

54.       lbl.setText ( ex + "" ) ; 

55.     } 

56.     ++nr; 

57.     nr = ( nr == 4  ?  0  :  nr ); 

58.   } 

59.  

60.  

61.   public void init() 

62.   { 

63.  

64.     lbl = new JLabel( "Ain't worth a thing ..." ); 

65.     tf = new JTextField ( "TextField Rangers", 20 ); 

66.     bt = new JButton ( "Change LookAndFeel" ) ; 

67.     cb = new JComboBox ( ); 

68.     sl = new JSlider ( JSlider.HORIZONTAL, 0, 100, 50 ) ; 

69.  

70.     pl= (JPanel) getContentPane ( ) ; 

71.  

72.     pl.setLayout ( new FlowLayout ( )  ); 

73.  

74.     lbl.setBackground ( Color.yellow ) ; 

75.     lbl.setOpaque ( true ) ; 

76.  

77.     cb.addItem ( "Uno" ); 

78.     cb.addItem ( "Due" ); 

79.     cb.addItem ( "Tre" ); 

80.  

81.     pl.add ( lbl ) ; 

82.     pl.add ( tf ) ; 

83.     pl.add ( bt ); 

84.     pl.add ( cb ) ; 

85.     pl.add ( sl ) ; 

86.  

87.     bt.addActionListener ( this ) ; 

88.     tf.addActionListener ( this ) ; 

89.  

90.     pl.setBackground( Color.cyan ); 

91.  

92.     tf.requestFocus ( ) ; 

93.   } 

94.

95.  

96.  

97.