/* 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 java.awt.event.* ; 

2. import java.awt.* ; 

3. import java.applet.*; 

4.  

5. public class TwoButtons 

6.   extends Applet 

7.   implements ActionListener 

8.

9.   TextArea ta ; 

10.   Button btuno, btdue ; 

11.  

12.   public void actionPerformed( ActionEvent ev ) 

13.   { 

14.     Object src = ev.getSource(); 

15.     if ( src == btuno ) 

16.       ta.append ( "\nUno  clicked" ); 

17.     else 

18.       ta.append ( "\nDue  clicked" ) ; 

19.  

20.   } 

21.  

22.   public TwoButtons () 

23.   { 

24.     btuno = new Button ( "Button uno" ) ; 

25.     btdue = new Button ( "Button due" ) ; 

26.     ta = new TextArea ( "This is a TextArea" , 6, 15 ) ; 

27.   } 

28.  

29.   public void init() 

30.   { 

31.     btuno.addActionListener ( this ) ; 

32.     btdue.addActionListener ( this ) ; 

33.     setBackground ( Color.lightGray ) ; 

34.  

35.     add ( btuno ) ; 

36.     add ( btdue ) ; 

37.     add ( ta ) ; 

38.     validate () ; 

39.   } 

40.  

41.