import javax.swing.*;
import java.awt.*;
public class BasicEventApplet extends JApplet 
{
	JButton button = new JButton("I'm active!");
	JPanel contentPanel = (JPanel)this.getContentPane();
	public void init() 
	{
		contentPanel.setLayout(new FlowLayout());
		contentPanel.add(button);
	}
}




import javax.swing.*;
import java.awt.*;
import java.awt.event.*;	// ActionListener & ActionEvent
public class BasicEventApplet extends JApplet 
implements ActionListener
{
	JButton button = new JButton("I'm active!");
	JPanel contentPanel = (JPanel)this.getContentPane();
	public void init() 
	{
		// arrange components
		contentPanel.setLayout(new FlowLayout());
		contentPanel.add(button);
	}
	// this satisfies the ActionListener interface
	public void actionPerformed(ActionEvent e)
	{
		// just beep, for now
		Toolkit.getDefaultToolkit().beep();
	}
}





import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BasicEventApplet extends JApplet 
implements ActionListener
{
	JButton button = new JButton("I'm active!");
	JPanel contentPanel = (JPanel)this.getContentPane();
	public void init() 
	{
		// register this class as an ActionEvent listener
		button.addActionListener(this);
		// arrange components
		contentPanel.setLayout(new FlowLayout());
		contentPanel.add(button);
	}
	// this satisfies the ActionListener interface
	public void actionPerformed(ActionEvent e)
	{
		// just beep, for now
		Toolkit.getDefaultToolkit().beep();
	}
}




import javax.swing.*;
import java.awt.event.*;
public class StatusApplet
   	extends JApplet
	implements ActionListener
{
 	JButton button = new JButton("Set Status");
	JTextField tfield  = new JTextField(20);
 	JPanel panel = new JPanel();
	
	public void init()
	{
		panel.add(tfield);
		panel.add(button);
		this.getContentPane().add(panel);
	}
	
	// satisifies implementation of ActionListener
	public void actionPerformed(ActionEvent evt)
	{
		this.showStatus(tfield.getText().trim());
	}
}





import javax.swing.*;
import java.awt.event.*;
public class StatusApplet extends JApplet
implements ActionListener
{
	final String CLEAR_STATUS = "clear_status";	
	final String CLEAR_FIELD = "clear_field";
	
	JButton button = new JButton("Set Status");
	JButton clearButton = new JButton("Clear");
	JTextField tfield  = new JTextField(20);
	JPanel	panel	= new JPanel();
	
	public void init()
	{
		button.addActionListener(this);
		clearButton.addActionListener(this);
		clearButton.setActionCommand(CLEAR_STATUS);
		tfield.addActionListener(this);
		panel.add(tfield);
		panel.add(button);
		panel.add(clearButton);
		this.getContentPane().add(panel);
	}
	
	// satisifies implementation of ActionListener
	public void actionPerformed(ActionEvent evt)
	{
		String command = evt.getActionCommand();
		if(command.equals(CLEAR_STATUS))
		{
	   		this.showStatus("");
			clearButton.setActionCommand(CLEAR_FIELD);
			return;
		}
		else if(command.equals(CLEAR_FIELD))
		{
			tfield.setText("");
			return;
		}
		this.showStatus(tfield.getText().trim());
		clearButton.setActionCommand(CLEAR_STATUS);
	}
}




import javax.swing.*;
public class MarathonApp
{
	JLabel label = new JLabel("It just keeps going, and going...");
	JFrame frame = new JFrame("MarathonApp Example");
	
	public MarathonApp () 
	{
		frame.getContentPane().add(label);
		frame.setSize(300,100);
		frame.setVisible(true);
		
		// ignore the following code-- 
		// it simply reminds the user we are running
		while(true)
		{
			try
			{
				Thread.sleep(1000);
				System.out.println("I'm still here!");
			}
			catch(InterruptedException ex)
			{
				// ignore
			}
		}
	}
	
	public static void main(String args[]) 
	{
		MarathonApp app = new MarathonApp();
	}
} 




import javax.swing.*;
import java.awt.event.*;
public class MarathonApp implements WindowListener
{
	JLabel label = new JLabel("It just keeps going, and going...");
	JFrame frame = new JFrame("MarathonApp Example");
	
	public MarathonApp () 
	{
		frame.addWindowListener(this);
		frame.getContentPane().add(label);
		frame.setSize(300,100);
		frame.setVisible(true);
	}
	public static void main(String args[]) 
	{
		MarathonApp app = new MarathonApp();
	}
	// all this, just to satisfy the interface definition
	public void windowActivated(WindowEvent e)
	{
		// ignore window activated events
	}
	public void windowDeactivated(WindowEvent e)
	{
		// ignore window deactivated events
	}
	public void windowIconified(WindowEvent e)
	{
		// ignore window iconified events
	}
	public void windowDeiconified(WindowEvent e)
	{
		// ignore window deiconified events
	}
	public void windowOpened(WindowEvent e)
	{
		// ignore window opened event
	}
	public void windowClosed(WindowEvent e)
	{
		// ignore window closed event
	}
	public void windowClosing(WindowEvent e)
	{
		// aha-- this I do care about!
		System.exit(0);
	}
}





import javax.swing.*;
import java.awt.event.*;
public class MarathonApp
{
	JLabel label = new JLabel("It just keeps going, and going...");
	JFrame frame = new JFrame("MarathonApp Example");
	MyWindowAdapter mwa = new MyWindowAdapter();
	
	public MarathonApp () 
	{
		frame.addWindowListener(mwa);
		frame.getContentPane().add(label);
		frame.setSize(300,100);
		frame.setVisible(true);
	}
	
	public static void main(String args[]) 
	{
		MarathonApp app = new MarathonApp();
	}
	
	// inner-class which handles our window events
	class MyWindowAdapter extends WindowAdapter
	{
		public void windowClosing(WindowEvent e)
		{
			System.exit(0);
		}
	}
}





import javax.swing.*;
import java.awt.event.*;
public class MarathonApp
{
	JLabel label = new JLabel("It just keeps going, and going...");
	JFrame frame = new JFrame("MarathonApp Example");
	
	public MarathonApp () 
	{
		frame.getContentPane().add(label);
		frame.setSize(300,100);
		frame.setVisible(true);
		frame.addWindowListener(
			new WindowAdapter()
			{
				public void windowClosing(WindowEvent e)
				{
		   			System.exit(0);
				}
			}
		);
	}
	
	public static void main(String args[]) 
	{
		MarathonApp app = new MarathonApp();
	}
}





import javax.swing.*;
import java.awt.*;
public class FocusApplet extends JApplet
{
	JPanel contentPanel = (JPanel)this.getContentPane();
	JPanel touchPanel = new JPanel();
	JLabel touchLabel = new JLabel("Active Region");
	
	public void init() 
	{
		touchLabel.setHorizontalAlignment(SwingConstants.CENTER);
		touchPanel.setBackground(Color.white);
		touchPanel.add(touchLabel);
		contentPanel.setLayout(new GridLayout(2,0));
		contentPanel.add(touchPanel);
	}
}





import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FocusApplet extends JApplet
{
	JPanel contentPanel = (JPanel)this.getContentPane();
	JPanel touchPanel = new JPanel();
	JLabel touchLabel = new JLabel("Active Region");
	MyMouseListener mml = new MyMouseListener();
	
	public void init() 
	{
		touchLabel.setHorizontalAlignment(SwingConstants.CENTER);
		touchPanel.setBackground(Color.white);
		touchPanel.add(touchLabel);
		touchPanel.addMouseListener(mml);
		contentPanel.setLayout(new GridLayout(2,0));
		contentPanel.add(touchPanel);
	}
	
	class MyMouseListener extends MouseAdapter
	{
		public void mouseEntered(MouseEvent e)
		{
	   	 	showStatus("Mouse entered Active Region");
		}
		public void mouseExited(MouseEvent e)
		{
	   	 	showStatus("Mouse exited Active Region");
		}
	}
}




import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FocusApplet extends JApplet
{
	JPanel contentPanel = (JPanel)this.getContentPane();
	JPanel touchPanel = new JPanel();
	JLabel touchLabel = new JLabel("Active Region");
	MyMouseListener mml = new MyMouseListener();
	MyMouseMotionListener mmml = new MyMouseMotionListener();
	
	public void init() 
	{
		touchLabel.setHorizontalAlignment(SwingConstants.CENTER);
		touchPanel.setBackground(Color.white);
		touchPanel.add(touchLabel);
		touchPanel.addMouseListener(mml);
		touchPanel.addMouseMotionListener(mmml);
		contentPanel.setLayout(new GridLayout(2,0));
		contentPanel.add(touchPanel);
	}
	
	class MyMouseListener extends MouseAdapter
	{
		public void mouseEntered(MouseEvent e)
		{
			showStatus("Mouse entered the Active Region");
		}
		public void mouseExited(MouseEvent e)
		{
			showStatus("Mouse exited the Active Region");
		}
	}
	class MyMouseMotionListener extends MouseMotionAdapter
	{
		public void mouseMoved(MouseEvent e)
		{
			showStatus("Mouse moved to location: x: "
				+ e.getX() + " y: " + e.getY());
		}
		public void mouseDragged(MouseEvent e)
		{
	   		 showStatus("Mouse dragged to location: x: "
				+ e.getX() + " y: " + e.getY());
		}
	}
}

