Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners applet tag requires code attribute.
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Pradyumna Sahoo
applet tag requires code attribute.
0 Answer(s)      2 years and 10 months ago
Posted in : Java Beginners


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;             

                          }



                            }

Advertisement
View Answers

Related Tutorials/Questions & Answers:
<applet> tag requires code attribute.
applet tag requires code attribute.  import java.applet.*; import java.awt.*; import java.awt.image.*; /*<applet code...="swsm.jpg"> <applet/>
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
The APPLET Tag in Detail
lets explore the APPLET tag now. The format of this tag is given below: [<... [</]APPLET[>]  <APPLET> Tag Attributes in detail.The three attributes of this tag are CODE/CODEBASE, WIDTH, and HEIGHT. One another point
applet program code - Applet
applet 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
attribute in action tag - Java Beginners
attribute 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 parameter - Applet
Applet 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
Rel attribute in area tag, Use of rel attribute in area tag.
Rel attribute in area tag, Use of rel attribute in area tag. In this tutorial, you will see the use of rel attribute of area tag and how to implement... : Declaration syntax of rel attribute in area tag.     
Target attribute in anchor tag, Use of target attribute of anchor tag in HTML5.
Target attribute in anchor tag, Use of target attribute of anchor tag in HTML5. In this tutorial, we will see the use of target attribute of anchor tag...; Declaration Syntax : Declaration syntax of target attribute in anchor tag.  
flush attribute in jsp:include tag - JSP-Servlet
flush attribute in jsp:include tag  what is the use of flush attribute in jsp:include tag ?  hi friend, ------------------------------ Read for more information, http://www.roseindia.net/jsp
Anchor tag attributes in HTML5, Define the type attribute of anchor tag.
  In this tutorial, we will see the use of type attribute of anchor tag . The type attribute of anchor tag specifies the MIME (multipurpose internet... syntax of type attribute in anchor tag.      
HTML5 audio loop, Use of loop attribute of audio tag in  HTML5.
HTML5 audio loop, Use of loop attribute of audio tag in  HTML5. Introduction:Loop attribute is used for reputation of audio or music. It repeats...; Example of  loop attribute in HTML5: Code: AudioLoop.html <
Rel attribute in anchor tag, Use of rel attribute in anchor tag.
Rel attribute in anchor tag, Use of rel attribute in anchor tag. Description:You will see the use of rel attribute of anchor tag and how to implement. The rel (relationship) attribute defines the relationship between current page
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
HTML5 type attribute, Definition of type attribute in <area> tag.
HTML5 type attribute, Definition of type attribute in <area> tag. This tutorial will inform you about <area>tag type attribute. The type... is set in the <area> tag. This attribute informs the browser about the type
HTML tags, Definition of applet tag in HTML5.
HTML tags, Definition of applet <applet> tag in HTML5. In this section, we will define applet tag. HTML5 does not support applet tag. Applet tag... instead of applet tag <applet>
HTML5 audio autobuffer, Use of autobuffer attribute in audio tag.
HTML5 audio autobuffer, Use of autobuffer attribute in audio tag. Introduction:The autobuffer attribute has Boolean value. It is available in audio tag...; <p><b>Example of audio tag autobuffer attribute in HTML5.</b><
Crop Image Code in Applet
Crop Image Code in Applet  Sir, Can somebody please provide me with code to crop and save an image in applet
Crop Image Code in Applet
Crop Image Code in Applet  Sir, Can somebody please provide me with code to crop and save an image in applet
applet code - Java Beginners
applet 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
HTML5 audio autoplay, Use of autoplay attribute in audio tag.
HTML5 audio autoplay, Use of autoplay attribute in audio tag. Introduction:The autoplay is an audio tag attribute. It is only supported by HTML5. When it is present in audio tag, the music file will begin itself. or After loading
Java code - Applet
Java code  I want java applet code for drawing an indian flag
Hreflang Attribute, Use of hreflang attribute of anchor tag in HTML5.
Hreflang Attribute, Use of hreflang attribute of anchor tag in HTML5.... Declaration Syntax : Declaration syntax of hreflang attribute in anchor tag...; Example of hreflang attribute: Code: hrefLangAttribute.html <
Anchor tag attributes in HTML5, Define the href attribute of anchor tag.
Anchor tag attributes in HTML5, Define the href attribute of anchor tag. In this tutorial, we will see the use of href attribute of anchor tag . The href attribute of anchor tag holds URL of destination document, which we want
JSP Applet Tag - JSP-Servlet
JSP 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
insertion sort applet code
insertion sort applet code  i need Insertion Sort Applet Program
servlet code - Applet
servlet 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
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
Java Code - Applet
Java Code  How to Draw various charts(Pie,Bar,and Line etc.)using Applet
html5 required attribute, Example of required attribute of &lt;textarea&gt; tag in html5
html5 required attribute, Example of required attribute of <textarea> tag in html5 In this tutorial, We will introduce you about the required attribute of the <textarea> tag in html5. This attribute is used to specify
html5 maxlength attribute, Example of maxlength attribute of &lt;textarea&gt; tag in html5
attribute of the <textarea> tag in html5. This attribute is used to specify...; Declaration Syntax:   The attribute is used as in the <textarea> tag...html5 maxlength attribute, Example of maxlength attribute of <textarea>
Code Problem - Applet
Code 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
Advertisements
 

 

 

DMCA.com