/**
 * @(#)Demo1GUI.java
 *
 * Demo1GUI Applet application
 *
 * @author Dissinger
 * @version 1.00 2008/7/15
 */
 
import java.awt.*;
import java.applet.*;
import java.awt.event.*; //needed for ActionListener

/*
 *The class needs to extend Applet. 
 *If you want to program events such as clicking buttons you need to 
 *implement ActionListener.
 */
public class Demo1GUI extends Applet implements ActionListener {
	Button btnClick; //declares btnClick as a Button
	TextField txt;
	
	//init = JAVA method and is executed when page loads - initializes LIKE MAIN!!!!
	public void init() {
		
		//The next 3 lines add the button	
		btnClick = new Button("Click Me"); 
		btnClick.setBounds(40,120,300,40);  //x,y, width, height
  		add(btnClick);  //JAVA method adds item to form
  		 		
  		//The next 3 lines add the textbox
  		txt = new TextField("Type something here and click button",  40);
  		txt.setBounds(40,0,200,30);
  		add(txt);
  		
  		btnClick.addActionListener(this); //Needed to program events for btnClick
	}
	
    //paint = JAVA method that is used to draw stuff on the screen
	public void paint(Graphics g) {	
		//The next line draws the text from the textbox onto the screen	
		g.drawString("THE TEXTBOX CONTAINS: " + txt.getText(), 50, 60 );		
	}
	
	//actionPerformed = JAVA method for programming events	
		public void actionPerformed(ActionEvent event){   
		/*The following code checks if btnClick is clicked
		*If it is clicked, the text from the textbox is
		* displayed on the page and on the button
		*/
  		if (event.getSource() == btnClick)  {
  			btnClick.setLabel(txt.getText());
  			repaint(); //Calls paint(). 
  			//Comment out the previous line and run. What happens?			
		}
	}
}
