Documente Academic
Documente Profesional
Documente Cultură
What is an Applet ?
APPLETS Vs APPLICATIONS
Java applications are simple and
alone programs that can run usi
Java interpreter from the comma
Java applets are run from inside
browser that supports applets.
STRUCTURE OF A SIMPLE
APPLET
By inheriting from
java.applet.Applet the necessary
structure is defined to
coordinate with a Web browser
My First Applet
Program
Create a java file called
firstapp.java
public class firstapp extends
java.applet.Applet { public void
init() { System.out.println("In
Panorama.init"); } }
Create a html file called
firstapp.html
<applet
code=firstapp
width=600 height=130>
</applet>
FONT CLASS
The font class represents fonts. T
Written inside an applet using diff
fonts.
An object of Font class is created
COLOR CLASS
By using some of the methods fro
class we can further enhance the
diagram and text inside the apple
using different colors.
The foreground and background c
also be set for an applet.
Example Program..
import java.awt.*;
public class Panorama extends
java.applet.Applet { Image img;
MediaTracker mt;
public void init() {
System.out.println("In Panorama.init");
img=getImage(getDocumentBase(),"Panoram
a.gif");
mt = new MediaTracker(this);
mt.addImage(img,0);
try {
mt.waitForAll();
} catch(InterruptedException e)
{ e.printStackTrace();
IMAGE ROTATION
ALGORITHM
SPECIFICATION
*Create a buffer with an
extension of dx columns
i = createImage(iw + dx, ih);
*Shift the image to the right dx
pixels
gc.copyArea(0, 0, iw, ih, dx, 0);
*Wrap the extension (of dx
pixels) back to the beginning
gc.copyArea(iw, 0, dx, ih, -iw,
mt = new MediaTracker(this);
mt.addImage(img,0);
try { mt.waitForAll(); }
catch(InterruptedException e)
{ e.printStackTrace(); }
iw = img.getWidth(null);
ih = img.getHeight(null);
buf =
createImage(iw+shift,ih);
bufg = buf.getGraphics();
bufg.drawImage(img,0,0,null);
advance();
RESULT
THREADING AND
ANIMATION
PROCESSES,
THREADS AND
ACTIVITIES
AN APPLET AS RUNNABLE
Many times an Applet will
have one additional (usually
continuous) activity, e.g.,
animation loop
In such cases it is quite likely
the class will both extend
Applet and implement
Runnable class ImgJump
extends Applet
BASIC ANIMATION
Animation is the display of a
series of pictures over time to
give the illusion of motion.
A basic computer animation
loop consists of
Advance to the next picture
(in an offscreen buffer)
Update the screen by
repainting it
Delay for some period of time
For example,
public void run( );
while (true) {
advance( ); // advance to
the next frame
repaint( ); // repaint the
screen
try
{ Thread.sleep(33); } // delay
catch(InterupptedException e)
Example Program
import java.awt.*;
public class move extends
java.applet.Applet implements
Runnable {
Image img;
MediaTracker mt;
int iw, ih;
Image buf;
int shift = 1;
Graphics bufg;
Thread t;
bufg = buf.getGraphics();
bufg.drawImage(img,0,0,null);
}
public void paint(Graphics g)
{ System.out.println("InPanora
ma.paint");
g.drawImage(buf,0,0,null);
}
public void advance() {
System.out.println
("In Panorama.advance");
bufg.copyArea(0,0, iw,ih,
PASSING PARAMETERS
TO AN APPLET
e.printStackTrace(); }
iw = img.getWidth(null);
ih = img.getHeight(null);
buf = createImage(iw+shift,ih);
bufg = buf.getGraphics();
bufg.drawImage(img,0,0,null);
}
public void paint(Graphics g)
{ System.out.println("InPanora
ma.paint");
g.drawImage(buf,0,0,null); }
public void advance()
System.out.println
(InPanorama.advance);
bufg.copyArea(0,0, iw,ih,
shift,0); bufg.copyArea(iw,0,
shift,ih, -iw,0); } public void
start() { System.out.println("In
Panorama.start"); t = new
Thread(this); t.start(); }
public void run()
{ System.out.println("In
Panorama.run"); while(true)
{ advance();
try { Thread.sleep(1);
} catch(InterruptedException
e)
{ e.printStackTrace(); return; }
}}
public void update(Graphics g)
{ paint(g);
In
} HTML file insert the tag param
different
properties.
}
<applet code=Panorama
width=600
height=130><param