applet tag requires code attribute.

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

Ads









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
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
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>
insertion sort applet code
insertion sort applet code  i need Insertion Sort Applet Program
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.  
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 <
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><
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
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
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
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
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
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 <
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
ModuleNotFoundError: No module named 'pandoc-code-attribute'
ModuleNotFoundError: No module named 'pandoc-code-attribute'  Hi...: No module named 'pandoc-code-attribute' How to remove the ModuleNotFoundError: No module named 'pandoc-code-attribute' error? Thanks   Hi
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>
HTML5 input attribute, Define the type, alt and image  of input tag.
HTML5 input attribute, Define the type, alt and image  of input tag. Introduction:Here we will introduce you to about the type attribute of input tag... attribute of input tag in HTML5.        
html5 placeholder attribute, Example of placeholder attribute of &lt;textarea&gt; tag in html5
html5 placeholder attribute, Example of placeholder attribute of <textarea> tag in html5 In this tutorial, We will introduce you about the placeholder attribute of the <textarea> tag in html5. This attribute is used
html5 readonly attribute, Example of readonly attribute of &lt;textarea&gt; tag in html5
; tag in html5 In this tutorial, We will introduce you about the readonly attribute of the <textarea> tag in html5. This attribute is used to specify...;  The attribute is used as in the <textarea> tag: <
html5 autofocus attribute, Example of autofocus attribute of &lt;textarea&gt; tag in html5
html5 autofocus attribute, Example of autofocus attribute of <textarea> tag in html5 In this tutorial, We will introduce you about the autofocus attribute of the <textarea> tag in html5. This attribute is used to specify
html5 disabled attribute, Example of disabled attribute of &lt;textarea&gt; tag in html5
; tag in html5 In this tutorial, We will introduce you about the disabled attribute of the <textarea> tag in html5. This attribute is used to specify...; The attribute is used as in the <textarea> tag: <textarea
Applet run with appletviewer but not in browser, any code problem.
Applet run with appletviewer but not in browser, any code problem.  Hi,My problem is when I am running my applet in appletviewer index.html, Its work... the 52 cards will be show in browser as by "appletviewer" and run as "java applet" I
In tag files,does attribute values accept expressions or not? If not please explain the reason
In tag files,does attribute values accept expressions or not? If not please... org.apache.jasper.JasperException: /demo1.jsp(20,5) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
Applet
Applet  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
HTML5 colspan attribute, Definition of colspan attribute of &lt;td&gt; tag in html5
HTML5 colspan attribute, Definition of colspan attribute of <td> tag in html5 In this discussion, We will introduce about the use of colspan attribute of <td> tag in html5. This attribute is used for specifying the number
HTML5 rowspan attribute, Definition of rowspan attribute of &lt;td&gt; tag in html5
HTML5 rowspan attribute, Definition of rowspan attribute of <td> tag in html5 In this discussion, We will introduce about the use of rowspan attribute of <td> tag in html5. This attribute is used for specifying the number

Ads