Solved

Scrolling text

Posted on 1998-12-24
9
229 Views
Last Modified: 2008-03-03
I have found an applet which display Fireworks. I would like to use it and have scrolling text displaying 'Welcome' with the Fireworks applet as my background. How do I do that?
0
Comment
Question by:suhani
  • 6
  • 3
9 Comments
 
LVL 16

Accepted Solution

by:
heyhey_ earned 100 total points
ID: 1230097
it seems that you are using a "ready-made" applet. In that case you can't change the applet behaviour, unless
1. you have the source code
2. the authors of the applet support some special HTML APPLET parameter (like PARAM scrollingtext)

do you need more information ?
(you can post the URL of the applet)
0
 

Author Comment

by:suhani
ID: 1230098
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1230099
you can get the source of the applet from the page above. Now everything depens on how much Java you know.
It is fairly easy to modify the applet (1-2 hours max) so to add the scrolling text. You probably can do it yourself. (if you need help - just ask). If you need me to do it, you'll have to describe EXACTLY what effect do you need, and increase the points to 100 ;-)

(of course I will help you doing this yourself, but I want more points for making it myself...)
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:suhani
ID: 1230100
OK, I'll increase your points to 100. Now can you please help me out. I need to get a word "WELCOME" scrolling vertically with the background of Firework applet.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1230101
;-)

ok - give me a few days ...
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1230102
sorry, I couldn't find this question during the weekend (I searched for it in the opened questions :(( )

stupid ... :(

ok - I'll post the code before next Monday

0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1230103
hi again.
I am posting the modified version of the applet.

you can easy change the message text and the message speed (higher values mean slower speed) in the HTML file.

I'm posting the .java file and the .html file.
If you don't have the appropriate tools to compile .java file to .class file, please contact me at heyhey@nettaxi.com, I'll e-mail you the whole working applet.

-------------- start of file Firework.java -----------------
import java.awt.*;
import java.applet.*;
import java.lang.*;
import java.util.*;
import java.net.*;

public class Firework extends Applet implements Runnable
{
public int AnimationSpeed,          
    RocketStyleVariability,          
    MaxRocketNumber,          
    MaxRocketExplosionEnergy,          
    MaxRocketPatchNumber,          
    MaxRocketPatchLength,          
    Gravity;

public String RocketSoundtrack;
private int mx,my;
private Thread thread=null;
private Rocket rocket[];

String mes;
int textSpeed;
private VertScrollingText text;
Image offScreenImage;
Graphics offScreenGraphics;

public void init()  
{
    int i;  
      String p, p2, p3;  
      p=getParameter("AnimationSpeed");  
      AnimationSpeed=(p==null)?100:Integer.valueOf(p).intValue();  
    RocketSoundtrack=getParameter("RocketSoundtrack");  
    p=getParameter("RocketStyleVariability");  
    RocketStyleVariability=(p==null)?20:Integer.valueOf(p).intValue();  
    p=getParameter("MaxRocketNumber");  
    MaxRocketNumber=(p==null)?5:Integer.valueOf(p).intValue();  
    p=getParameter("MaxRocketExplosionEnergy");  
    MaxRocketExplosionEnergy=(p==null)?500:Integer.valueOf(p).intValue();  
    p=getParameter("MaxRocketPatchNumber");  
    MaxRocketPatchNumber=(p==null)?50:Integer.valueOf(p).intValue();  
    p=getParameter("MaxRocketPatchLength");  
    MaxRocketPatchLength=(p==null)?100:Integer.valueOf(p).intValue();  
    p=getParameter("Gravity");  
    Gravity=(p==null)?20:Integer.valueOf(p).intValue();  
    p=getParameter("TextMessage");  
    mes=(p==null)?"Welcome":p;
    p=getParameter("TextSpeed");  
    textSpeed=(p==null)?3:Integer.valueOf(p).intValue();

    mx=size().width-1;  
    my=size().height-1;  
    rocket=new Rocket[MaxRocketNumber];  

    for(i=0;i<MaxRocketNumber;i++)
        rocket[i]=new Rocket(mx,my,Gravity);  
       
    text = new VertScrollingText(mes, new Font("Serif", Font.BOLD, 24), Color.cyan, textSpeed);
    Rectangle rect = this.getBounds();
    text.init(rect);
    offScreenImage = createImage(rect.width, rect.height);
    offScreenGraphics = offScreenImage.getGraphics();
}


public void start()  
{  
    if(thread==null)      
    {      
        thread=new Thread(this);      
        thread.start();      
    }  
}

public void stop()  
{  
    if(thread!=null)      
    {      
        thread.stop();      
        thread=null;      
    }  
}

public void run()  
{  
    int i,      
    e=(int)(Math.random()*MaxRocketExplosionEnergy*3/4)+         MaxRocketExplosionEnergy/4+1,      
    p=(int)(Math.random()*MaxRocketPatchNumber*3/4)+         MaxRocketPatchNumber/4+1,      
    l=(int)(Math.random()*MaxRocketPatchLength*3/4)+         MaxRocketPatchLength/4+1;  
    long s=(long)(Math.random()*10000);  
    boolean sleep;  
    Graphics g=getGraphics();  
    URL u=null;  

    while(true)      
    {      
        try
        {          
            thread.sleep(100/AnimationSpeed);          
        }      
        catch(InterruptedException x){}      

        sleep=true;      
        for(i=0;i<MaxRocketNumber;i++)        
            sleep=sleep&&rocket[i].sleep;      
           
        if(sleep&&Math.random()*100<RocketStyleVariability)        
        {        
            e=(int)(Math.random()*MaxRocketExplosionEnergy*3/4)+           MaxRocketExplosionEnergy/4+1;        
            p=(int)(Math.random()*MaxRocketPatchNumber*3/4)+           MaxRocketPatchNumber/4+1;        
            l=(int)(Math.random()*MaxRocketPatchLength*3/4)+           MaxRocketPatchLength/4+1;        
             s=(long)(Math.random()*10000);        
        }
       
       
        offScreenGraphics.setColor(Color.black);  
        offScreenGraphics.fillRect(0,0,mx+1,my+1);  
        text.show(offScreenGraphics);
       
        for(i=0;i<MaxRocketNumber;i++)        
        {        
            if(rocket[i].sleep&&Math.random()*MaxRocketNumber*l<1)  
            {            
                try
                {                
                    u=new URL(getDocumentBase(),RocketSoundtrack);
                }            
                catch(MalformedURLException x){}            
                play(u);            
                rocket[i].init(e,p,l,s);            
                rocket[i].start();            
            }        
        rocket[i].show(offScreenGraphics);        
        }      
    g.drawImage(offScreenImage, 0, 0, null);
    }  
}


public void paint(Graphics g)  
{  
    g.setColor(Color.black);  
    g.fillRect(0,0,mx+1,my+1);  
}

}


class Rocket
{
public boolean sleep=true;
private int energy,patch,length,            
mx,my,            gravity,            
ox,oy,            vx[],vy[],            
x,y,            red,blue,green,            t;

private Random random;

public Rocket(int a,int b,int g)  
{  
    mx=a;  
    my=b;  
    gravity=g;  
}

public void init(int e,int p,int l,long seed)  
{  
    int i;  
    energy=e;  
    patch=p;  
    length=l;  
    random=new Random(seed);  
    vx=new int[patch];  
    vy=new int[patch];  
    red=(int)(random.nextDouble()*128)+128;  
    blue=(int)(random.nextDouble()*128)+128;  
    green=(int)(random.nextDouble()*128)+128;  
    ox=(int)(Math.random()*mx/2)+mx/4;  
    oy=(int)(Math.random()*my/2)+my/4;  
    for(i=0;i<patch;i++)      
    {      
        vx[i]=(int)(Math.random()*energy)-energy/2;      
        vy[i]=(int)(Math.random()*energy*7/8)-energy/8;      
    }  
}

public void start()  
{  
    t=0;  
    sleep=false;  
}

public void show(Graphics g)  
{  
    if(!sleep)      
    if(t<length)        
    {        
        int i,c;        
        double s;        
        Color color;        
        c=(int)(random.nextDouble()*64)-32+red;        
        if(c>=0&&c<256)red=c;        
        c=(int)(random.nextDouble()*64)-32+blue;        
        if(c>=0&&c<256)blue=c;        
        c=(int)(random.nextDouble()*64)-32+green;        
        if(c>=0&&c<256)green=c;        
        color=new Color(red,blue,green);        
        for(i=0;i<patch;i++)            
        {            
            s=(double)t/100;            
            x=(int)(vx[i]*s);            
            y=(int)(vy[i]*s-gravity*s*s);            
            g.setColor(color);            
            g.drawLine(ox+x,oy-y,ox+x,oy-y);            
            if(t>=length/2)              
            {              
                int j;              
                for(j=0;j<2;j++)                  
                {                  
                    s=(double)((t-length/2)*2+j)/100;                  
                    x=(int)(vx[i]*s);                  
                    y=(int)(vy[i]*s-gravity*s*s);                  
                    g.setColor(Color.black);                  
                    g.drawLine(ox+x,oy-y,ox+x,oy-y);                  
                }              
            }            
        }        
        t++;        
    }      
    else        
    {        
       sleep=true;        
    }  
}
}


class VertScrollingText
{
public boolean sleep=true;
private String mes;
private Font font;
private Color color;

private int strWidth, strHeight;
private int width, height;
private int curX, curY;
private int textSpeed;
private int t;

public VertScrollingText (String theMes, Font theFont, Color theColor, int theSpeed)
{
    mes = theMes;
    font = theFont;
    color = theColor;
    textSpeed = theSpeed;
    t = theSpeed;
    FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics (font);
    strHeight = fm. getHeight();
    strWidth = fm.stringWidth(mes);
}

public void init(Rectangle size)
{
    width = size.width;
    height = size.height;
   
    curX = (width - strWidth) / 2;
    curY = height + strHeight ;
}

public void show(Graphics g)
{
    if (curY > -strHeight)
    {    
        g.setFont(font);
        g.setColor(color);
        g.drawString(mes, curX, curY);
        t--;
        if (t == 0)
        {
            t = textSpeed;
            curY--;
        }
    }
    else
    {
        curY = height + strHeight ;
    }
}

}
-------------- end of file Firework.java -----------------

-------------- start of file Firework.html -----------------
<HTML>
<head>
<title>test page </title>
</head>

<body bgcolor="#ffffff" text="#000000" link="#cc0000" vlink="#999999">

<center><h1>new Firework</h1>
<hr>
<APPLET CODE="Firework.class" WIDTH="399" HEIGHT="349">
<PARAM NAME="AnimationSpeed" VALUE="50">
<PARAM NAME="RocketSoundtrack" VALUE="fire.au">
<PARAM NAME="RocketStyleVariability" VALUE="10">
<PARAM NAME="MaxRocketNumber" VALUE="9">
<PARAM NAME="MaxRocketExplosionEnergy" VALUE="850">
<PARAM NAME="MaxRocketPatchNumber" VALUE="90">
<PARAM NAME="MaxRocketPatchLength" VALUE="68">
<PARAM NAME="Gravity" VALUE="400">
<PARAM NAME="TextMessage" VALUE="Welcome suhani">
<PARAM NAME="TextSpeed" VALUE="4">

</applet>
<hr></center>
<b>Usage:</b>
Place <a href="Firework.class" target="_top"><b>Firework.class</a></b> ,
<a href="Rocket.class" target="_top"><b>Rocket.class</a></b> and
<a href="VertScrollingText.class" target="_top"><b>VertScrollingText.class</a></b>
(along with <b><a href="fire.au">fire.au</a></b>) within your HTML directory.
<p>
<b>Java Source:</B>  <a href="Firework.java" target="_top">Firework.java</a><p>
<B>HTML Source:</B>
<pre>&lt;APPLET CODE="Firework.class" WIDTH="399" HEIGHT="349"&gt;
&lt;PARAM NAME="AnimationSpeed" VALUE="50"&gt;
&lt;PARAM NAME="RocketSoundtrack" VALUE="fire.au"&gt;
&lt;PARAM NAME="RocketStyleVariability" VALUE="10"&gt;
&lt;PARAM NAME="MaxRocketNumber" VALUE="9"&gt;
&lt;PARAM NAME="MaxRocketExplosionEnergy" VALUE="850"&gt;
&lt;PARAM NAME="MaxRocketPatchNumber" VALUE="90"&gt;
&lt;PARAM NAME="MaxRocketPatchLength" VALUE="68"&gt;
&lt;PARAM NAME="Gravity" VALUE="400"&gt;
&lt;PARAM NAME="TextMessage" VALUE="Welcome !!!"&gt;
&lt;PARAM NAME="TextSpeed" VALUE="11"&gt;
&lt;/applet&gt;</pre>
<P>
<B>Author:</B>  David O'Brien
<P>
<B>Modified:</B>  heyhey


<P>
<hr>

</BODY>
</HTML>
-------------- end of file Firework.html -----------------

best regards
  heyhey
0
 

Author Comment

by:suhani
ID: 1230104
Wonderful! Thank you. However, I need one more favour. How do you make the messages to be scrolled in different lines and each lines has different font and colors.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1230105
take a better look at the VertScrollingText class

 VertScrollingText (String theMes, Font theFont, Color theColor, int theSpeed)

the message nad the color are filled in the constructor !!!

and all the moving algorithm and drawing is in te show() method

you can write your own HorzScrollingText class - it's fairly easy.

you can create more than one textScrolling object and add it to the applet - you'll need only to call their COnstructo / init / show method.

(take a look at the third line - it makes the real drawing of the Scroling text in the applet
>> offScreenGraphics.setColor(Color.black);    
>> offScreenGraphics.fillRect(0,0,mx+1,my+1);    
>> text.show(offScreenGraphics);
)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question