24, అక్టోబర్ 2022, సోమవారం

 A practical session on APPLETS by RAMU @DAYINA ,CLX     

A Sample program on Applet Images

E:\java trails>appletviewer imgapp.java

APPLET IS CREATED JUST NOW

THE CODE BASE IS file:/E:/java%20trails/

THE DOCUMETN BASE IS file:/E:/java%20trails/imgapp.java

APPLET STOPPED     SESSION-1   in the below program applet and lifecycle methods image insertions and codebase docbases like urls

import java.awt.*;

import java.applet.*;

import java.net.*;// added this package for URL class

/*<applet code=imgapp  width =400 height=400 ></applet>*/

public class imgapp extends Applet

{

Image i; // to load the Image into the variable

URL u,u1;// from which location we load the image c:\ or d:\ramu\

int w,h;// width and height of the Applet

 

public void init()

{

setBackground(Color.yellow);//to set background as yellow and foreground as pink

setForeground(Color.pink);

System.out.println("APPLET IS CREATED JUST NOW");

 

u=getCodeBase();

u1=getDocumentBase();

System.out.println("THE CODE BASE IS "+u.toString());//it will give FOLDER information information where the applet file exists

System.out.println("THE DOCUMETN BASE IS "+u1.toString()); // it will give the full path including the filename

i=getImage(u,"1.gif"); /*here from our folder i am loading the Image into Image class for this i passed parameters u [folder path],image filename after i is passed to g.drawString() method ,starting pair,ending pair of

coordinates, on which applet [this] means to the current applet frame*/

w=getWidth();

h=getHeight();

}


public void strart()

{System.out.println("APPLET IS STARTED");}

public void  paint(Graphics g)

{

g.drawString("WELCOME TO APPLET WORLD",30,200);

g.drawString("WELCOME TO APPLET ",50,208);

g.drawString("WELCOME TO ",30,216);

g.drawString("WELCOME ",10,232);

showStatus("THIS IS Mr.D.RAMANJANEYULU"+w + h);

showStatus("PLAYING A SONG"+w + h);   this message will be displayed on the statusbar before status statement will be overridded

g.drawImage(i,20,20,this); // in the output first image 20,20 height and width from the begining verify

g.drawImage(i,0,0,w,h,this);// second picture which will start from the (0,0) and (w,h)

g.drawImage(i,200,200,w,h,this);//third image will get printed on the browser from the starting location as (200,200)and ending is(w,h)

update(g);   // write when the update willbe called USE

}

//repaint() method calling situation

public void update(Graphics g)

{}

 

public void stop()

{

System.out.println("APPLET STOPPED");

}

public void destroy()

{

System.out.println("APPLET IS DESTROYED");

}

}


కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి