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

6.     extends JApplet 

7.     implements ActionListener 

8.

9.   JLabel lbl ; 

10.   JTextField tf ; 

11.   JButton bt ; 

12.   JPanel pl ; 

13.  

14.   public void init( ) 

15.   { 

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

17.     tf = new JTextField ( "innit ??", 20 ); 

18.     bt = new JButton ( "JLessons button" ) ; 

19.  

20.     pl= (JPanel) getContentPane ( ) ; 

21.  

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

23.  

24.     lbl.setBackground ( Color.green ) ; 

25.     lbl.setOpaque ( true ) ; 

26.  

27.     pl.add ( lbl ) ; 

28.     pl.add ( tf ) ; 

29.     pl.add ( bt ); 

30.  

31.     bt.addActionListener ( this ) ; 

32.     tf.addActionListener ( this ) ; 

33.  

34.     pl.setBackground( Color.yellow ); 

35.      

36.     validate (); 

37.  

38.     tf.requestFocus ( ) ; 

39.   } 

40.  

41.   public void actionPerformed ( ActionEvent ev ) 

42.   { 

43.     pl.setBackground ( Color.cyan ) ; 

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

45.   } 

46.