//======================================================================//	PROJECT:			_programming.java_//	FILE:				Ovenator.java//	PURPOSE:			Chapter 4 lablet//	VERSION:			1.1//	TARGET:				Java v1.1//	UPDATE HISTORY:		1.1		9/22/98		new documentation and 1.1 compliance//						1.0		10/9/97		the version in _p.j_//======================================================================//------------------------------- NOTES --------------------------------/*	We're exploring the use of layouts and containers to give us finer	control over the look of our applets, but the most obvious feature	of this lablet is that we have defined five helper classes	to supplement the Ovenator applet.		Even though we don't plan to reuse these classes in any other	applet, they're still useful since they make the design process	simpler.  Instead of having to decide what to do with ten buttons	and a canvas for painting the time, we organize our applet	into conceptually related groups, each having its own layout:			ControlPanel			(all the controls)			TimeCanvas			(for drawing the time display)			TimeButtonsPanel	(four buttons to set the time)			CoolButtonsPanel	(four buttons to set the mode)			StartStopPanel		(start and stop buttons)*///------------------------------ IMPORTS -------------------------------import java.awt.*;import java.applet.*;//========================== Ovenator CLASS ============================/** * Our oven is simply a control panel and a drawing of a door. */public class Ovenator extends Applet {	ControlPanel myControls = new ControlPanel();		/**	 * We use a border layout here so that we can position the	 * control panel on the right ("East") side of the applet frame.	 */	public void init() 	{      	setBackground(Color.darkGray);      	setLayout(new BorderLayout());            	add("East", myControls);	}		/**	 * Paint the oven door and logo directly on the applet	 * frame, using the current size of the applet.	 */	public void paint(Graphics g)   	{		Dimension mySize = getSize();      	   		g.setColor(Color.black);   		g.fill3DRect(5, 5, mySize.width - 135, mySize.height -10, true);    		g.setColor(Color.yellow);   		g.setFont(new Font("Helvetica", Font.ITALIC, 24));   		g.drawString("The Ovenator",10, mySize.height - 25);   	} }//======================== ControlPanel CLASS ==========================/** * This is the main control panel for the oven.  It has 4 parts: *   timeDisplay: a canvas where we paint the time *   timeButtons: a panel with a collection of buttons for setting the time *   cookButtons: a panel containing buttons for choosing the cook mode *   myStartStop: a panel with two buttons for starting and stopping * * Note that we don't need a paint() method in this class, since it's * nothing but a container for objects that already "know" how to * paint themselves. */class ControlPanel extends Panel {	TimeCanvas			timeDisplay = new TimeCanvas(); 	TimeButtonsPanel	timeButtons = new TimeButtonsPanel();	CookButtonsPanel	cookButtons = new CookButtonsPanel();	StartStopPanel		startStop = new StartStopPanel();        /**     * To construct a ControlPanel object, we set the colors     * to a high-tech yellow-on-black and use a grid layout     * to place the four subassemblies in a single columns.     *     * Since this class isn't an applet, it doesn't have an init()     * method.  Instead, to set the initial values and properties we     * use a "constructor"--a method with no return type and     * the same name as the class.  This method will be      * invoked whenever we make a declaration like     *     ControlPanel myControls = new ControlPanel();     * as we did above in the data portion of the Ovenator applet.     */  	public ControlPanel()	{   		setBackground(Color.black);		setForeground(Color.yellow);      	setLayout(new GridLayout(4,1));      	setSize(125,300);            	add(timeDisplay);      	add(timeButtons);      	add(cookButtons);     	add(startStop);	}}//========================= TimeCanvas CLASS ===========================/** * This class is just a graphics area containing no widgets. * In a working oven simulation, we would continually update * the displayed time.  You'll learn how to do that in Chapter 11. */class TimeCanvas extends Canvas{   	/**	 * To initialize a TimeCanvas object, all we have to do is	 * create a white canvas.  The real work here is done when	 * the paint() method is called.	 */   	public TimeCanvas()	{		setBackground(Color.white);   	}   	/**	 * Draw our "current time" and position it using the canvas size.	 */   	public void paint(Graphics g)   	{   		Dimension mySize = getSize();   		g.setColor(Color.black);   		g.draw3DRect(2, 2, mySize.width - 5, mySize.height - 5, true);   		g.setColor(Color.red);		g.setFont(new Font("Helvetica", Font.BOLD, 30));   		g.drawString("00:00", 12, 45);   	} }//====================== TimeButtonsPanel CLASS ========================/** * This panel consists of four buttons arranged in a  * single row (hence, the grid layout).  */class TimeButtonsPanel extends Panel {   	Button	b10Minutes = new Button("10"),   			b1Minute = new Button("1"),   			b10Seconds = new Button("10"),   			b1Second = new Button("1");      	public TimeButtonsPanel()   	{      	setLayout(new GridLayout(1,4));            	add(b10Minutes);      	add(b1Minute);      	add(b10Seconds);      	add(b1Second);	}}//====================== CookButtonsPanel CLASS ========================/** * This panel holds the four "cook" buttons in a one-column grid.  */class CookButtonsPanel extends Panel  {   	Button	bMicro = new Button("Micro"),   			bDefrost = new Button("Defrost"),   			bTimer = new Button("Timer"),   			bClock = new Button("Clock");      	public CookButtonsPanel()   	{      	setLayout(new GridLayout(4,1));            	add(bMicro);      	add(bDefrost);      	add(bTimer);      	add(bClock);   	}}//====================== CookButtonsPanel CLASS ========================/** * This panel holds a pair of buttons in a single row.  */class StartStopPanel extends Panel {   	Button	bStop = new Button("Stop"),   			bStart = new Button("Start");      	public StartStopPanel()   	{      	setLayout(new GridLayout(1,2));            	add(bStop);      	add(bStart);   }}