Solved

Scrolling text

Posted on 1998-12-24
9
227 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 71
Starting to learn JAVA, 7 59
get weblogic logged in user in java 2 58
how do i compare an object based on two fields 6 49
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

920 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now