Java displays the current system time _java

Source: Internet
Author: User

Write applet applets that display the current system time in different colors and fonts by receiving parameters in an HTML document.

Ex4_1.java

Import java.awt.*; 
Import Java.applet.Applet; 
Import Java.util.Calendar; 
 
public class Ex4_1 extends applets 
{ 
 Calendar now; 
 Private String S1; 
 private int size,color; 
  
 public void init () 
 { 
  now=calendar.getinstance ();  Gets the system current time 
  S1=now.get (now. HOUR) + "Time" 
  +now.get (now. MINUTE) + "min" 
  +now.get (now. SECOND) + "seconds"; 
  Size=integer.parseint (getparameter ("size"))//Get font size 
  color=integer.parseint (getparameter ("Color"), 16);// Gets the color value 
 } public 
  
 void Paint (Graphics g) 
 {color 
  c=new color (color); 
  G.setcolor (c); 
  Font f=new font ("", 1,size); 
  G.setfont (f); 
  g.DrawString (s1,10,50);   Displays the string for the specified size color 
 } 

Ex4_1.html

 
 

Run Effect chart:

A simple small program to do so, we can change according to their preferences font and color, I hope to learn Java programming help OH.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.