/** * TimeEntryPanel provides a data entry panel for Latitude and Longitude. * It is always expressed by a subclass (LatitudeField or LongitudeField)<p> * * Copyright &copy; 1998-89 Martin Minow. All Rights Reserved.<p> * * Permission to use, copy, modify, and redistribute this software and its * documentation for personal, non-commercial use is hereby granted provided that * this copyright notice and appropriate documentation appears in all copies. This * software may not be distributed for fee or as part of commercial, "shareware," * and/or not-for-profit endevors including, but not limited to, CD-ROM collections, * online databases, and subscription services without specific license.<p> * * Based on DateGUI.java in Mastering JavaBeans. * @see <a href="http://www.sybase.com">Sybase</a>, click on *  "Catalog>Updates>Mastering JavaBeans". * @author <a href="mailto:minow@pobox.com">Martin Minow</a> * @version 1.0a0 * Set tabs every 8 characters. */package org.minow.applets.sunsphere;import java.beans.*;import java.util.*;import java.awt.*;import java.awt.event.*;import java.text.*;public class TimeEntryPanel extends Panel{    protected IntegerField	hourField;    protected IntegerField	minuteField;    protected IntegerField	secondField;        protected long	    	value;		/* Time in msec.	*/        public TimeEntryPanel()    {	this(System.currentTimeMillis());    }    public TimeEntryPanel(    	    Date		javaDate    	)    {    	this(javaDate.getTime());    }    public TimeEntryPanel(    	    long		value	)    {		hourField	= new IntegerField(3, 0, 0, 24);	minuteField	= new IntegerField(2, 0, 0, 59);	secondField	= new IntegerField(2, 0, 0, 59);	/*	 * Construct the display Panel.	 */	GridBagLayout gridbag	= new GridBagLayout();	setLayout(gridbag);	GridBagConstraints c	= new GridBagConstraints();	c.gridy			= 0;	c.weightx		= 0.0;	c.anchor		= GridBagConstraints.WEST;	c.fill			= GridBagConstraints.NONE;	addField(c, hourField);	addField(c, new Label(":"));	addField(c, minuteField);	addField(c, new Label(":"));	addField(c, secondField);	setTime(value);    }    private void addField(	    GridBagConstraints	c,	    Component			component	)    {	add(component);	((GridBagLayout) getLayout()).setConstraints(component, c);    }    /*     * Accessor functions.     */    public void setTime(	    long		value	)    {	this.value		= value % 86400000;	displayTime();    }    public long getTime()    {	try {	    int seconds		= Integer.parseInt(secondField.getText());	    int minutes		= Integer.parseInt(minuteField.getText());	    int hours		= Integer.parseInt(hourField.getText());	    value		=	    		(hours     * 3600000)	    		+ (minutes *   60000)	    		+ (seconds *    1000);	    		;	}	catch (NumberFormatException e) { }	return (value);    }    /*     * Update the display to reflect the new values.     * Note: we only support degrees, minutes, and seconds.     */    protected void displayTime()    {    	int seconds		= (int) ((value / 1000) % 60);    	int minutes		= (int) ((value / 60000) % 60);    	int hours		= (int) ((value / 3600000));	hourField.setText(String.valueOf(hours));	minuteField.setText(String.valueOf(minutes));	secondField.setText(String.valueOf(seconds));    }	}