applet tag requires code attribute.
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
/*<applet code=Lavatron.class width=590 height=130>
<param name="img" value="swsm.jpg">
<applet/>
*/
public class Lavatron extends Applet implements Runnable{
int scrollX;
int bulbsW,bulbsH;
int bulbS=8;
Dimension d;
Image offscreen,bulb,img;
Graphics offgraphics;
int pixels[];
int pixscan;
IntHash clut=new IntHash();
boolean stopFlag;
public void init(){
d=getSize();
int offw=(int) Math.ceil(d.width/bulbS)* bulbS;
int offh=(int) Math.ceil(d.height/bulbS)* bulbS;
offscreen=createImage(offw,offh);
offgraphics=offscreen.getGraphics();
bulbsW=offw/bulbS;
bulbsH=offh/bulbS;
bulb=createBulbs(bulbS,bulbsH*bulbS);
try{
img=getImage(getDocumentBase(),getParameter("img"));
MediaTracker t= new MediaTracker(this);
t.addImage(img, 0);
t.waitForID(0);
pixscan=img.getWidth(null);
int h=img.getHeight(null);
pixels=new int[pixscan *h];
PixelGrabber pg= new PixelGrabber(img,0,0,pixscan,h,pixels,0,pixscan);
pg.grabPixels();
}catch(InterruptedException e){};
scrollX=0;
offgraphics.setColor(Color.black);
offgraphics.fillRect(0,0,d.width,d.height);
for(int x=0;x<bulbsW;x++)
offgraphics.drawImage(bulb,x*bulbS,0,null);
}
Image createBulbs(int w,int h){
int pixels[]=new int[w*h];
int bulbBits[]={
0,0,1,1,1,1,0,0,
0,1,2,1,1,1,1,0,
1,2,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
0,1,1,1,1,1,1,0,
0,0,1,1,1,1,0,0};
int bulbCLUT[]={0xff000000,0x00c0c0c0,0xffffffff};
for(int i=0;i<w*h;i++)
pixels[i]=bulbCLUT[bulbBits[i % bulbBits.length]];
return createImage(new MemoryImageSource(w,h,pixels,0,w));
}
public final Color color(int x,int y){
int p=pixels[y*pixscan+x];
Color c;
if((c=(Color)clut.get(p))==null)
clut.put(p,c=new Color(p));
return c;
}
public void update(){}
public void paint(Graphics g){
offgraphics.copyArea(bulbS,0,bulbsW*bulbS-bulbS,d.height,-bulbS,0);
for(int y=0;y<bulbsH;y++){
offgraphics.setColor(color(scrollX,y));
offgraphics.fillRect(d.width-bulbS,y*bulbS,bulbS,bulbS);
}
offgraphics.drawImage(bulb,d.width-bulbS,0,null);
g.drawImage(offscreen,0,0,null);
scrollX=(scrollX+1) % pixscan;
}
Thread t;
public void run(){
while(true){
paint(getGraphics());
try{
t.yield();
}catch(Exception e){};
if(stopFlag)
break;
}
}
public void start(){
t=new Thread(this);
t.setPriority(Thread.MIN_PRIORITY);
stopFlag=false;
t.start();
}
public void stop(){
stopFlag=true;
}
}
class IntHash{
private int capacity;
private int size;
private float load=0.7f;
private int keys[];
private Object vals[];
public IntHash(int n){
capacity =n;
size=0;
keys=new int[n];
vals=new Object[n];
}
public IntHash(){
this(101);
}
private void rehash(){
int newcapacity=capacity*2+1;
Object newvals[]=new Object[newcapacity];
int newkeys[]=new int[newcapacity];
for(int i=0;i<capacity;i++){
Object o=vals[i];
if(o!=null){
int k=keys[i];
int newi=(k & 0x7fffffff) % newcapacity;
while(newvals[newi]!=null)
newi=(newi + 1) % newcapacity;
newkeys[newi]=k;
newvals[newi]=o;
}
}
capacity=newcapacity;
keys=newkeys;
vals=newvals;
}
public void put(int k,Object o){
int i=(k & 0x7fffffff) % capacity;
while(vals[i]!=null && k!=keys[i])
i=(i+1) % capacity;
if(vals[i]==null)
size++;
keys[i]=k;
vals[i]=o;
if(size>(int)(capacity*load))
rehash();
}
public final Object get(int k){
int i= (k & 0x7fffffff) % capacity;
while(vals[i]!=null && k!=keys[i])
i=(i+1) % capacity;
return vals[i];
}
public final boolean contains(int k){
return get(k)!=null;
}
public int size(){
return size;
}
public int capacity(){
return capacity;
}
}
View Answers
Related Tutorials/Questions & Answers:
Applet Tag Parameters,Applet Tag in HTML the
applet's operation.
APPLET parameters stored in the PARAM
tag actually have little....
Second, add necessary
code to the
applet to retrieve these parameter values... <APPLET>
Tag Parameters: The <PARAM>
Tag Advertisements
applet program code - Appletapplet program code hello sir,
i did't get the
code for below problem... please help me...
1.An
applet program to draw a line graph for y=2x+5.[for suitable values of x & y
The APPLET Tag in Detail the
applet's code.
The document's URL is used.
if this
attribute... lets explore the
APPLET tag
now. The format of this
tag is given below:
[<...
[</]
APPLET[>]
<APPLET>
Tag Attributes in detail.The three
Applet code parameter - AppletApplet code parameter Hi...
I've designed an
applet where i placed...
How can i get that class...
I used
code="MyProgram.class" codebase="WEB-INF/classes"
but this didn't worked
i also tried
code="WEB
attribute in action tag - Java Beginnersattribute in action tag I'm just a beginner to struts.
The name
tag(name="bookListForm") is used to define the form used with the action class. But i`m not clear about the
attribute tag(
attribute applet code - Java Beginnersapplet code hi friends..
i have to oen one
applet, in that
applet code should be apper what we have written for the
applet... this is my...://www.roseindia.net/java/example/java/
applet/
Hope that it will be helpful
Crop Image Code in AppletCrop Image
Code in Applet Sir,
Can somebody please provide me with
code to crop and save an image in
applet Crop Image Code in AppletCrop Image
Code in Applet Sir,
Can somebody please provide me with
code to crop and save an image in
applet servlet code - Appletservlet code how to communicate between
applet and servlet Hi Friend,
We are providing you the
code that will display the message sent from the servlet to
applet.
Here is the
code of 'ServletExample.java
JSP Applet Tag - JSP-ServletJSP
Applet Tag Hi,
I am using Eclipse Ganymede. I have develloped... and my
applet(Basic Hello World
Applet) under Java Resources folder. I have jsp plugin type as
applet in my jsp. When I run this jsp on Server(Tomcat6.0
HTML5 <area> href, hreflang attribute of area tag.;area>
tag in html5.
href:
The href
attribute specifies the URL link for the area
tag in the image map; each
tag have a link.
hreflang:
This
attribute...;
The
attribute value refers to the language
code, which is two letter
Code Problem - AppletCode Problem How to set a background color for frame and panel ...?
What is the difference btw these two(in setting background color)..? Hi Friend,
If you simply want to set background color for panel, try
Custom Tag example with no attribute and no body
Custom
Tag example with no
attribute and no body... to make custom
tag with no
attribute
and no body
This example demonstrates how one can make custom
tag in JSP that has no
attribute and no body. There are only
Achor tag. Struts2 code - StrutsAchor
tag. Struts2 code Hi All,
How to send the values form one jsp page to another using anchor
tag (or any which is similar to achor) in Struts? Please help me. I am waiting for the answer.
Regards,
Sandeep
AppletApplet I have a java
applet that has a button. On clicking the button it should disappear and another
applet should appear. How to write this
code???? Also in login
applet after successful login it should display admin
applet Achor tag. Struts2 code - StrutsAchor
tag. Struts2 code Hi All,
How to send the values form one jsp page to another using anchor
tag (or any which is similar to achor) in Struts? Please help me. I am waiting for the answer.
Regards,
Sandeep
AppletApplet Write an
applet to display a string in an
applet. String should be passed as a parameter to an
applet appletapplet What is the immediate superclass of the
Applet class
appletapplet Explain different stages in the lifecycle of an
applet with figure.
Stages of
Applet:
Life cycle of an
Applet:
init(): This method is called to initialized an
applet
start(): This method is called after
AppletApplet Give the class hierarchy of an
Applet class
AppletApplet how to run an
applet on a web browser