public class Testing extends Thread implements Runnable
{
public static void main(String[] args)
{
Thread runner = new Thread();
Thread bannerThread new Thread();
///////// start the threads //////////////
two.setPriority(one.getPriority() + 4);
one.start();
two.start();
}
}
class bannerThread extends Thread
// public class ScrollingBanner extends java.applet.Applet implements Runnable
{
// Thread bannerThread;
String text;
Font font = new java.awt.Font("Times New Roman", Font.BOLD, 30);
int x, y;
int delay = 20;
int offset = 1;
Dimension d;
public void init() {
// get parameters "delay" and "text"
String att = getParameter("delay");
if (att != null) {
delay = Integer.parseInt(att);
}
att = getParameter("text");
if (att != null) {
text = att;
} else {
text = "Buy More at Nathan Chan Movie Buy";
}
// set initial position of the text
d = getSize();
x = d.width * 3;
y = 100;
}
public void paint(Graphics g) {
// get the font metrics to determine the length of the text
g.setFont(font);
FontMetrics fm = g.getFontMetrics();
int length = fm.stringWidth(text);
// adjust the position of text from the previous frame
x -= offset;
// if the text is completely off to the left end
// move the position back to the right end
if (x < -length)
x = d.width;
// set the pen color and draw the background
g.setColor(Color.white);
g.fillRect(0,0,d.width,d.height);
// set the pen color, then draw the text
g.setColor(Color.blue);
g.drawString(text, x, y);
}
public void start() {
bannerThread = new Thread(this);
bannerThread.start();
}
public void stop() {
bannerThread = null;
}
public void run() {
while (Thread.currentThread() == bannerThread) {
try {
Thread.currentThread().sleep(delay);
}
catch (InterruptedException e) {}
repaint();
}
}
}
class runner extends Thread
// public class MovieBuyScroll extends JApplet implements Runnable
{
Image austinpics[] = new Image[8];
Image currentimg;
Thread runner;
int xpos;
int ypos = 50;
Thread bannerThread;
String text;
Font font = new Font("Times New Roman", Font.BOLD, 30);
int xpos2, ypos2;
int delay = 200;
int offset = 1;
Dimension d;
public void init()
{
// put the gif names into array
String apowerssrc[] = {"apowers30.jpg","apowers31.jpg","apowers32.jpg","apowers33.jpg",
"apowers34.jpg","apowers35.jpg","apowers36.jpg",
"apowers37.jpg"};
// use the jpeg names in the above array to build up
// an array of jpeg images
for(int i =0; i < apowerssrc.length; i++)
{
austinpics[i] = getImage(getCodeBase(), apowerssrc[i]);
}
}
public void start()
{
if (runner == null)
{
runner = new Thread(this);
runner.start();
}
}
public void stop()
{
if (runner != null)
{
runner.stop(); //stop thread every time stop is called
runner = null; //as the user leaves for another web page
}
}
public void run() // run the animation
{
setBackground(Color.white);
while(true)
{
austinpowers1(0,getWidth());
austinpowers2(getWidth(),getWidth());
austinpowers1(xpos, getWidth());
austinpowers2(0, getWidth());
}
}
void austinpowers1(int start, int end)
{
for(int i = start; i < end; i+=30)
{
xpos = i; // move the image to xpos = i
if(currentimg == austinpics[0])
{currentimg = austinpics[1];
repaint();
pause(delay);
currentimg = austinpics[2];
repaint();
pause(delay);
currentimg = austinpics[3];
repaint();
pause(delay);
currentimg = austinpics[4];
repaint();
pause(delay);
currentimg = austinpics[5];
repaint();
pause(delay);
currentimg = austinpics[6];
repaint();
pause(delay);
currentimg = austinpics[7];
repaint();
pause(delay);
currentimg = austinpics[0];
repaint();
pause(delay);
}
else
{currentimg = austinpics[1];
repaint();
pause(delay);
currentimg = austinpics[2];
repaint();
pause(delay);
currentimg = austinpics[3];
repaint();
pause(delay);
currentimg = austinpics[4];
repaint();
pause(delay);
currentimg = austinpics[5];
repaint();
pause(delay);
currentimg = austinpics[6];
repaint();
pause(delay);
currentimg = austinpics[7];
repaint();
pause(delay);
currentimg = austinpics[0];
repaint();
pause(delay);
} // close else
} // close for loop
} // close austinspowers1
void austinpowers2(int start, int end)
{
for(int i = start; i > end; i-=30)
{
xpos = i;
if(currentimg == austinpics[0])
{currentimg = austinpics[1];
repaint();
pause(delay);
currentimg = austinpics[2];
repaint();
pause(delay);
currentimg = austinpics[3];
repaint();
pause(delay);
currentimg = austinpics[4];
repaint();
pause(delay);
currentimg = austinpics[5];
repaint();
pause(delay);
currentimg = austinpics[6];
repaint();
pause(delay);
currentimg = austinpics[7];
repaint();
pause(delay);
currentimg = austinpics[0];
repaint();
pause(delay);
}
else
{currentimg = austinpics[1];
repaint();
pause(delay);
currentimg = austinpics[2];
repaint();
pause(delay);
currentimg = austinpics[3];
repaint();
pause(delay);
currentimg = austinpics[4];
repaint();
pause(delay);
currentimg = austinpics[5];
repaint();
pause(delay);
currentimg = austinpics[6];
repaint();
pause(delay);
currentimg = austinpics[7];
repaint();
pause(delay);
currentimg = austinpics[0];
repaint();
pause(delay);
} // close else
} // close for loop
} // close austinspowers1
void pause(int time)
{
try { Thread.sleep(time); }
catch (InterruptedException e) {}
}
public void paint(Graphics g)
{
g.clearRect(0,0,getWidth(),getHeight());
g.drawImage(currentimg,xpos,ypos,this);
}
}