aspose file tools*
The moose likes Java in General and the fly likes Java ScrollBanner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java ScrollBanner " Watch "Java ScrollBanner " New topic
Author

Java ScrollBanner

Brijesh Shah
Ranch Hand

Joined: Aug 08, 2006
Posts: 34
HI ,

I have a code here below:
import java.awt.*;
import java.applet.*;
/*
<applet code="ScrollBanner" width=600 height=300>
<param name=message1 value="A Simple Banner Number ONE. ">
<param name=message2 value="A Simple Banner Number TWO. ">
</applet>
*/
public class ScrollBanner extends Applet implements Runnable
{
String msg1, msg2;
Font f;
int x1=100, y1=50, x2=100, y2=200;
Thread t=null;
boolean stopFlag;

// Set font, colors and initialize the applet thread and prepare to start
public void init()
{
msg1=getParameter("message1");
if (msg1 == null)
{
msg1="Missing parameter message.";
}
msg1=" "+msg1;
msg2=getParameter("message2");
if (msg2 == null)
{
msg2="Missing parameter message.";
}
msg2=" "+msg2;
f=new Font("Arial, Helvetica", Font.BOLD,18);
setFont(f);
setBackground(Color.yellow);
setForeground(Color.red);
}// closing init()

// Start the scroll banner applet running, creating a new thread as necessary
public void start()
{
t=new Thread(this);
stopFlag=false;
t.start();
}// closing start()

/** Entry point for the thread that runs the banner. This method
* repaints the message repeatedly, which will cause it to move across
* the display. To save CPU, it sleeps between repaint operations.
*/
public void run()
{
char ch1,ch2;

// Display the banner moving
for ( ; ; )
{
try
{
repaint();
Thread.sleep(250);
ch1=msg1.charAt(0);
msg1=msg1.substring(1,msg1.length());
msg1=msg1+ch1;
if(stopFlag)
break;
}
catch(InterruptedException e)
{
// Prints this throwable and its backtrace to the standard error stream (System.err)
e.printStackTrace();
}
try
{
//repaint();
Thread.sleep(250);
ch2=msg2.charAt(0);
msg2=msg2.substring(1,msg2.length());
msg2=msg2+ch2;
if(stopFlag)
break;
}
catch(InterruptedException e)
{
// Prints this throwable and its backtrace to the standard error stream (System.err)
e.printStackTrace();
}
}// closing for()
}// closing run()

// Stop the scroll banner applet running
public void stop()
{
stopFlag=true;
t=null;
}// closing stop()

// Paint the applet with the message text
public void paint(Graphics g)
{
g.drawString(msg1,x1,y1);
g.drawString(msg2,x2,y2);
}// closing paint()
}// closing class SimpleBanner

In the above code I want to move 2 applet banners one moving from left to right and another right to left .
I am having trouble for coding for the banner moving from left to right.
Could you please assist...
Thanks in advance!!!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
After a quick look at this ... are they both moving right to left now? Looks like removing the first character and adding it to the end works for that. The opposite would take the last character and move it to the front. Look carefully at the arguments for substring and look into length.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Brijesh Shah
Ranch Hand

Joined: Aug 08, 2006
Posts: 34
hi

If I interchange the substring statement it isn't working:

try
{
//repaint();
Thread.sleep(250);
ch2=msg2.charAt(0);
msg2=msg2.substring(msg2.length(),1);
msg2=msg2+ch2;
if(stopFlag)
break;
}
catch(InterruptedException e)
{
// Prints this throwable and its backtrace to the standard error stream (System.err)
e.printStackTrace();
}
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
ch2=msg2.charAt(0);//you need the last character

msg2=msg2.substring(msg2.length(),1);//problem, see below

msg2=msg2.substring(1,msg2.length());//from first post
this line creates a string, excluding the first char
you want the excluded char to be the last
(hint: deduct 1 from both above args)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java ScrollBanner