SESSION-1 in the below program
applet and lifecycle methods image insertions and codebase docbases like urls
,set fonts,setting of colors
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
Font f=new Font("Times New
Roman",Font.BOLD+Font.ITALIC,80);//here i am creating my own font settings
public void init()
{
setBackground(Color.yellow);
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.setFont(f);//for all printing
strings by default it will be applicable
g.drawString("WELCOME TO APPLET
WORLD",200,100);
g.setColor(Color.BLUE);//here for
every line i am changeing the color settings
g.drawString("WELCOME TO APPLET
",200,400);
g.setColor(Color.green);
g.drawString("WELCOME TO chirala
",200,600);
g.setColor(Color.gray);
g.drawString("WELCOME
Mr.D.Ramanjaneyulu",600,200);
showStatus("THIS IS
Mr.D.RAMANJANEYULU"+w + h); //if we write more statements for the status
window then last will show the result
showStatus("PLAYING A
SONG"+w + h);
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");
}
}
Output:-
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
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి