Skip to content

Instantly share code, notes, and snippets.

@abiduzz420
Last active April 5, 2017 10:09
Show Gist options
  • Save abiduzz420/1fa27f5eb609a00b52c02f03a2d03583 to your computer and use it in GitHub Desktop.
Save abiduzz420/1fa27f5eb609a00b52c02f03a2d03583 to your computer and use it in GitHub Desktop.
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
/*
<applet code = "SampleApplet" width = 300 height = 50>
</applet>
*/
public class SampleApplet extends Applet implements Runnable {
private String msg;
private Thread thread;
private boolean stopFlag;
public void init()
{
msg = "Top to bottom moving banner. ";
thread = null;
setForeground(Color.magenta);
}
public void start()
{
thread = new Thread(this);
stopFlag = false;
thread.start();
}
public void run()
{
int x,y;
for(;;)
{
try{
repaint();
x = getX();
y = getY();
Thread.sleep(60);
if(stopFlag)
break;
setLocation(x,y+1);
/*
To move diagonally, increement/decreement x & y parameters.
setLocation(x+1,y-2);
*/
}catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
public void stop()
{
stopFlag = true;
thread = null;
}
public void paint(Graphics g)
{
int x = 10;
int y = 50;
g.drawString(msg,x,y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment