当前位置: 移动技术网 > IT编程>开发语言>Java > java显示当前的系统时间

java显示当前的系统时间

2019年07月22日  | 移动技术网IT编程  | 我要评论

编写applet小程序,通过在html文档中接收参数,用不同颜色、字体显示当前的系统时间。

ex4_1.java

import java.awt.*; 
import java.applet.applet; 
import java.util.calendar; 
 
public class ex4_1 extends applet 
{ 
 calendar now; 
 private string s1; 
 private int size,color; 
  
 public void init() 
 { 
  now=calendar.getinstance();  //获得系统当前时间 
  s1=now.get(now.hour)+"时" 
  +now.get(now.minute)+"分" 
  +now.get(now.second)+"秒"; 
  size=integer.parseint(getparameter("size"));//获得字体大小 
  color=integer.parseint(getparameter("color"),16); //获得颜色值 
 } 
  
 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);   //显示指定大小颜色的字符串 
 } 
} 

ex4_1.html

<html> 
<applet code="ex4_1.class" width=300 height=100> 
<param name=s1 value=s1> 
<param name=size value=30> 
<param name=color value=007000> 
</applet> 
</html> 

运行效果图:

一个简单的小程序就这样完成了,大家可以根据自己喜好改变字体和颜色,希望对大家学习java编程有所帮助哦。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网