Java Display Numerical Values in Applet


In applets, we can display numerical values by first converting them into strings and then using the drawstring() method of Graphics class we can do this easily by calling the valueOf() Method of String class.

Example

import java.awt.*;
import java.applet.*;
public class DisplayNumericalValues extends Applet
{
	public void paint(Graphics g)
	{
		int val1 = 10;
		int val2 = 20;    	
		int sum = val1 + val2;
        String str_sum = "Sum="+String.valueOf(sum);
        g.drawString(str_sum,100,200);
	}
}

This applet runs using the following HTML file:

<HTML>
<HEAD>
	<TITLE>Display Numerical Values</TITLE>
</HEAD>
<BODY>
	<APPLET Code="DisplayNumericalValues.class" Width=400 Height=300>
	&/APPLET>
<BODY>    
</HTML>
Output

Share this article on