Vertical Scroll a Shape

No Comment - Post a comment

/* Java Program To Move a Shape say Oval from the bottom of the applet to the center, a vertical scroll in an infinite loop ie once the shape reaches the denter it goes back to the bottom and repeats the path */

import java.awt.*;
import java.applet.*;

public class VertiScroll extends Applet implements Runnable
{
int x,y;
Dimension size;

public void init()
{
//set initial co-ordinates for message
x = 230;
y = 450;
//creates new thread
Thread t = new Thread(this);
t.start();
}
public void run()
{
while (true)
{
try
{
/*initialize size to contain the current size of the applet window */

size = getSize();
/* if co-ordinate of the oval is lesser than reset the height of the applet the x coordinate to a value say 200 else decrement y */

if(y< 200)
y = 450;
y--;
Thread.sleep(20);
}
catch(InterruptedException e)
{
}
repaint();
}
}

public void paint(Graphics g)
{
g.setColor(Color.red);
g.fillOval(x,y,40,50);
}
}

/*< applet code=VertiScroll Width=500 Height = 500>< /applet>*/

 

Horizontal Scroll Text - 2

No Comment - Post a comment

/* Program In Java To Display A text and to scroll the text from left to right, display the text as colored */

import java.awt.*;
import java.applet.*;

public class HoriScroll2 extends Applet implements Runnable
{
String message = "Pay-Per-Play Starts on Feburary....";
int x,y;
Dimension size;

public void init()
{
//set initial co-ordinates for message
x = 300;
y = 50;
//creates new thread
Thread t = new Thread(this);
t.start();
}
public void run()
{
while (true)
{
try
{
/*initialize size to contain the current size of the applet window */

size = getSize();
/* if co-ordinate of the text is lesser than a value say 5 reset the width of the applet the x coordinate to 500 else decrement x */

if(x< 5)
x = 500;
x--;
Thread.sleep(50);
}
catch(InterruptedException e)
{
}
repaint();
}
}

public void paint(Graphics g)
{
g.setFont(new Font("Terminal",Font.BOLD|Font.ITALIC,26));
g.setColor(Color.green);
g.drawString(message,x,y);
}
}

/*< applet code=HoriScroll2 Width=500 Height = 500>< /applet>*/

 

Horizontal Scroll Text

1 comments - Post a comment

/* Program In Java To Display A text and to scroll the text from right to left, display the text as colored */

import java.awt.*;
import java.applet.*;

public class HoriScroll extends Applet implements Runnable
{
String message = "Lionel Cyril ....";
int x,y;
Dimension size;

public void init()
{
//set initial co-ordinates for message
x = 10;
y = 50;
//creates new thread
Thread t = new Thread(this);
t.start();
}
public void run()
{
while (true)
{
try
{
/*initialize size to contain the current size of the applet window */

size = getSize();
/* if co-ordinate of the text is greater than reset the width of the applet the x coordinate to 10 else increment x */

if(x>size.width)
x = 0;
x++;
Thread.sleep(50);
}
catch(InterruptedException e)
{
}
repaint();
}
}

public void paint(Graphics g)
{
g.setFont(new Font("Monotype Corsiva",Font.BOLD,24));
g.setColor(Color.red);
g.drawString(message,x,y);
}
}

/*< applet height="500" width="500" code="HoriScroll">< /applet>*/