I have written a Java applet, which works as a news ticker. The
direction of the scroll is from bottom to up (by default). The applet is
highly customizable. You can, by changing paramArgs value, incorporate
as many URLs as desired. The index of the Text, URL pair however, begins
with the 0 and not from 1, thus special care must be taken care while
writing so. paramDelay can be used to control the speed of the ticker.
The default values (for the arguments/parameters) will be overridden
when you specify the new at the time of implementation. You can check
out one implementation by looking at the source code of this page by
going through View > Source Code. A sample run of this applet is being
shown below for your reference.
The source code of Skroll.java is as follows:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
/*
*/
public class Skroll extends Applet implements Runnable, MouseListener
{
int arg, y, index, Delay;
String Text[], Url[], Direction;
Thread t = null;
AppletContext ac;
public void init()
{
//setBackground(Color.white);
Direction = getParameter("paramDirection");
addMouseListener(this);
try
{
arg=Integer.parseInt(getParameter("paramArgs"));
Delay = Integer.parseInt(getParameter("paramDelay"));
}
catch(NumberFormatException e)
{
}
//Local vars to catch params
String TextL[] = new String[arg];
String UrlL[] = new String[arg];
for (int i=0; i= 70)
{
y=0;
if (index == (arg-1))
index = 0;
else
index++;
}
else
y++;
}
if (y==18)
{
try
{
Thread.sleep(Delay);
}
catch(InterruptedException e)
{
}
}
else
{
try
{
Thread.sleep(30);
}
catch(InterruptedException e)
{
}
}
}
}
public void paint(Graphics g)
{
//setForeground(Color.black);
g.drawRect(1,1,Integer.parseInt(getParameter("Width"))-2,25);
//setForeground(Color.red);
//g.fillRect(4,4,28,21);
g.drawString(Text[index], 40, y);
}
public void mouseEntered(MouseEvent me)
{
//setBackground(Color.yellow);
showStatus(Url[index]);
}
public void mouseExited(MouseEvent me)
{
//setBackground(Color.white);
showStatus(" ");
}
public void mousePressed(MouseEvent me)
{
}
public void mouseReleased(MouseEvent me)
{
}
public void mouseClicked(MouseEvent me)
{
try
{
ac.showDocument(new URL(Url[index]));
}
catch(MalformedURLException e)
{
showStatus("URL not found");
}
}
}
|