How to write string in java applet programs ?

Hello friends,My name is vivek and in this post i will show that how to write string in java applet programs.

Program that prints a “Hello,World” using java applet :

 

package applet_one;

import java.awt.*;
import java.applet.*;
/*
<applet code="AppDemo0" height=700 width=800>
</applet>
*/
public class Applet_One extends Applet {

            public void init() {
                   // Initialize the applet
                
               setBackground(Color.darkGray);
               setForeground(Color.CYAN);
            }

            public void paint(Graphics g) {
               g.drawString("Hello World!", 10, 30);
            }

         } 

OUTPUT:
Capture

As you can see in above code setBackground(); method sets the color of background of java applet and setForeground(); method sets the color of foreground of java applet.

In Paint method whatever you write that displays in java applet, as you can see that drawString(); method writes the string or we can say that sets the string value in applet,the attribute 10 and 30 sets the distance from x as well as y direction.

Leave a Reply

Your email address will not be published. Required fields are marked *