Your browser does not support the HTML canvas tag.



Home

//******************************************************************************
// project7.for.java:	Applet
//
//******************************************************************************
import java.applet.*;
import java.awt.*;
public class project7 extends Applet
{
	String     sDate,
		       sTime,
		       sAMPM;
	
	Button     btnUpdate;
	
	TextField  txtDate,
	           txtTime;
	
	Date       dtMyDate;

public project7()
{
// TODO: Add constructor code here
}

public String getAppletInfo()
{
	return "Name: project7\r\n" +
	       "Author: \r\n" +
	       "Created with Microsoft Visual J++ Version 6.0";
}

public void init()
{
	sDate	= new String("");
	sTime	= new String("");
	
	resize( 300, 32 );
	
	btnUpdate = new Button("Update Time");
	
	txtDate   = new TextField ("Some Date", 10);
	txtTime   = new TextField ("Some Time", 12);
	
	add(btnUpdate);
	
	add(txtDate);
	add(txtTime);
		

// TODO: Place additional initialization code here
}

public void paint(Graphics g)
{
	g.setColor ( new Color (50, 50, 50) );
	g.fillRect ( 0, 0, 300, 33 );
	
	g.setColor ( new Color (100, 100, 100) );
	g.fillRect ( 5, 5, 290, 22 );
}

public void start()
{
// TODO: Place additional applet start code here
}

public void stop()
{
}

public boolean action ( Event e, Object o )
{
	if (e.target.equals( btnUpdate ) )
	  { 
		dtMyDate = new Date();
		
		sDate  = String.valueOf(dtMyDate.getMonth()+1)  + "/";
		sDate += String.valueOf(dtMyDate.getDate())     + "/";
		sDate += String.valueOf(dtMyDate.getYear()+1900);
				
		int i = dtMyDate.getHours();
		int j = dtMyDate.getMinutes();
		int k = dtMyDate.getSeconds();
		
		if ( i > 12 ) 
		{sTime  = String.valueOf(i-12)    + ":"; 
		sAMPM = " PM";
		}
		else { sTime  = String.valueOf(i)    + ":"; 
		sAMPM = " AM";
		}
		
		if ( j < 10 ) 
		{sTime  += "0" + String.valueOf(j) + ":"; }
		else { sTime  += String.valueOf(j) + ":"; }
		
		if ( k < 10 ) 
		{sTime  += "0" + String.valueOf(k) + sAMPM;}
		else { sTime  += String.valueOf(k) + sAMPM; }
		
		
		
		
		
		txtDate.setText( sDate );
		txtTime.setText( sTime );
	  }
			
	return true;
}

}