Write an Applet applet to display the current system time in different colors and fonts by receiving parameters in the HTML document.
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(); //Get the current system time s1=now.get(now.HOUR)+"hour" +now.get(now.MINUTE)+"minute" +now.get(now.SECOND)+"seconds"; size=Integer.parseInt(getParameter("size"));//Get the font size color=Integer.parseInt(getParameter("color"),16); / /Get 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); //Display a string of specified size and color} }
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>
Operation rendering:
A simple small program is completed in this way. You can change the font and color according to your own preferences. I hope it will be helpful to everyone in learning java programming.