//======================================================================//	PROJECT:			_programming.java_//	FILE:				Borders.java//	PURPOSE:			Chapter 2 lablet, new version//	VERSION:			2.0//	TARGET:				Java v1.1//	UPDATE HISTORY:		2.0		9/3/98		completely different//						1.0		4/21/96		the version in _p.j_//======================================================================//------------------------------- NOTES --------------------------------/*	We're using some of the graphics routines to draw borders of	different sizes in response to mouse clicks.  There's some fancy	(and potentially confusing) stuff going on in the actionPerformed()	method, but we don't want you to worry about the details for now.	Instead, just concentrate on the drawing we do in the paint() method.*///------------------------------ IMPORTS -------------------------------/*	Notice that we're importing the same packages we did in the	Chapter 1 lablet.*/import java.applet.*;import java.awt.*;import java.awt.event.*;//=========================== Borders CLASS =============================/** * The Borders applet is very similar to the Colors applet of Chapter 1. * However, instead of changing the background and text color in response * to button clicks, this applet responds to mouse clicks by growing or * shrinking a decorative border drawn directly on the applet frame. */public class Borders extends Applet implements ActionListener{	//------------------------------ DATA ------------------------------		private	int		inset = 5,			// amount of border inset, in pixels					MAX = 50,			// the largest allowable inset					MIN = 5;			// the smallest allowable inset	private	boolean	shrinking = true;	// whether we're shrinking or growing	private	Button	resizeBttn;			// shrinks or grows the border		//---------------------------- METHODS -----------------------------		/**	 * Initialize this applet. All we have to do is make a new button,	 * add it to the applet, and register the applet ("this") as the	 * listener for action events.	 */	public void init() 	{		resizeBttn = new Button("Smaller!");		add(resizeBttn);		resizeBttn.addActionListener(this);	}		/**	 * Respond to a click on our only button.  In this case, we don't	 * need to check where the action event came from, since it could	 * only have come from the button.	 */	public void actionPerformed(ActionEvent e) 	{		//----- Change the inset size by +5 or -5 pixels.				if (shrinking)			// If we're shrinking the frame, increase inset		{			inset = inset + 5;		}		else					// otherwise, decrease the inset.		{			inset = inset - 5;		}				//----- If we're now at max or min inset, take appropriate action.				if (inset == MAX)		// If we're now at max inset...		{			resizeBttn.setLabel("Larger!");	// change the button label,			shrinking = false;				// and change direction flag.		}		else if (inset == MIN)	// If we're now at min inset....		{			resizeBttn.setLabel("Smaller!");			shrinking = true;		}			repaint();	// Force a call to paint, to show the new border.	}		/**	 * Redraw the border, using the applet's dimension and the	 * inset to tell us how to draw the rectangles. 	 */	public void paint(Graphics g) 	{		// Find out how big the applet is, and use that to compute the		// x, y anchor and w, h extent of the drawable area.		// NOTE: We're using local variables here, since appletSize,		// x, y, w, and h are only used in this method, and nowhere else.		Dimension appletSize = getSize();		int	x = 0,			y = 30,			w = appletSize.width - x,			h = appletSize.height - y;					// Draw the outer red rectangle (always the same size).			g.setColor(Color.red);		g.fillRect(x, y, w, h);				// Draw the black edge lines, inset as necessary.		g.setColor(Color.black);		g.drawRect(x + inset, y + inset, w - 2 * inset, h - 2 * inset);				// Draw the inner border, just inside the black lines		g.setColor(Color.white);		g.fillRect(x + inset + 1, y + inset + 1, w - 2 * inset - 2, h - 2 * inset - 2);				// Finally, draw the internal region in a color of our own.		Color fillColor = new Color(255, 200, 200);		g.setColor(fillColor);		g.fillRect(x + inset + 6, y + inset + 6, w - 2 * inset - 12, h - 2 * inset - 12);		}	}		