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

3. import java.awt.*; 

4. import java.awt.event.*; 

5. import java.net.*; 

6.  

7. public class SwCharac 

8.       extends JApplet 

9.       implements ActionListener 

10.

11.   JPanel  pl ; 

12.   JLabel  lbl = new JLabel( "=========LBL=========" ); 

13.   JTextField  tf = new JTextField ( "6124357", 15 ); 

14.   JButton  bt = new JButton ( "Press me" ) ; 

15.  

16.   public void init() 

17.   { 

18.     JMenuBar mb = new JMenuBar() ; 

19.  

20.     JMenu men = new JMenu ( "Doit" ) ; 

21.  

22.     JMenuItem mi1st = new JMenuItem ( "First Choice" ) ; 

23.     men.add ( mi1st ) ; 

24.     men.addSeparator() ; 

25.  

26.     JMenuItem mi2nd = new JMenuItem ( "Second Choice" ) ; 

27.     mi2nd.addActionListener ( this ) ; 

28.     men.add ( mi2nd ) ; 

29.  

30.     mb.add ( men ) ; 

31.  

32.     setJMenuBar ( mb ) ; 

33.  

34.     lbl.setBackground ( Color.green ) ; 

35.     lbl.setOpaque ( true ) ; 

36.     Border bor = 

37.      BorderFactory.createLineBorder ( Color.blue, 5 ) ; 

38.     lbl.setBorder ( bor ); 

39.  

40.     try

41.     URL uim = new URL ( getCodeBase(), "pic.gif" ); 

42.     ImageIcon ic = new ImageIcon ( uim ); 

43.     bt.setIcon ( ic ); 

44.     } 

45.     catch ( MalformedURLException ex ) 

46.     { System.err.println ( ex ); } 

47.  

48.     tf.setToolTipText ( "Data entry here" ) ; 

49.     tf.setHorizontalAlignment ( JTextField.RIGHT ) ; 

50.  

51.     pl= (JPanel) getContentPane() ; 

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

53.     pl.setBorder 

54.     ( BorderFactory.createMatteBorder 

55.       ( 15, 30, 45, 60, Color.white ) ); 

56.     pl.add ( lbl ); 

57.     pl.add ( tf ); 

58.     pl.add ( bt ); 

59.     pl.setBackground( Color.yellow ); 

60.  

61.     setGlassPane ( new OurGP() ) ; 

62.  

63.     tf.requestFocus ( ) ; 

64.   } 

65.  

66.   public void actionPerformed ( ActionEvent ev ) 

67.   { 

68.     pl.setBackground ( Color.cyan ) ; 

69.     lbl.setText ( tf.getText ( )  ) ; 

70.     getGlassPane().setVisible ( true ) ; 

71.   } 

72.

73.  

74. class OurGP 

75.   extends JComponent 

76.

77.   public void paintComponent( Graphics gr ) 

78.   { 

79.     super.paintComponent( gr ); 

80.     int w=getSize().width; 

81.     int h=getSize().height; 

82.     int y=h/4

83.     gr.setColor( Color.darkGray ); 

84.     gr.setFont(new Font("Monospaced",Font.BOLD,18) ); 

85.     for ( int x=20; x < w/2+50;  x+=5, y+=4

86.     { 

87.       gr.drawLine( x, y, x+30, y-20 ); 

88.       if ( x % 15 == 0

89.         gr.drawString( "on top", x+5, y ); 

90.     } 

91.   } 

92.

93.  

94.  

95.