Displaying Numerical values in Applets

Displaying  Numerical  values  :

In  applets ,  we can  display  numerical values  by  first converting  them  in to  string is   then  using the  drawString  ( ) method of  Graphics  class.  We  can  do  this  easily by  calling the  valueOf  (  ) method  of  String  class.

Program  :

import  java  . awt.*;
import  java . applet  .* ;
public  class  NumValues  extends   Applet
{
 public  void  paint  (  Graphics    g)
 {
    int value1=  10;
    int value2= 20;
    int  sum= value1+  value2;
    String    s  = “sum:”  + tSring. valueOf  (sum);
    g.  drawString    (5,100,100) ;
   }
 }

When  run  using   the  following    HTML  file  displays  the  output

 <  html  >
  <  applet >
   Code  =  NumValues. class.
    Width    =300
    Height   =300 >
 < /  applet  >
 <   /  html >


Related

Java 6354964078728269830

Post a Comment

emo-but-icon

item