Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* A sample banner applet.
- This applet creates a thread that scrolls
- the message contained in msg right to left
- across the applet's window.
- */
- import java.awt.*;
- import java.applet.*;
- /* <applet code="SampleAppletBanner" width=300 height=100>
- </applet>
- */
- public class SampleAppletBanner extends Applet implements Runnable
- { String msg="A sample moving banner";
- Thread t=null;
- int state;
- boolean stopFlag;
- // Set colors and intialize thread
- public void start()
- { t=new Thread(this);
- stopFlag=false;
- t.start();
- }
- // Entry point for the thread that runs the banner
- public void run()
- { char ch;
- // Display banner
- for( ; ;)
- { try
- { repaint();
- Thread.sleep(250);
- ch=msg.charAt(0);
- msg=msg.substring(1,msg.length());
- if(stopFlag)
- break;
- }
- catch(InterruptedException e)
- {}
- }
- }
- // Pause the banner
- public void stop()
- { stopFlag=true;
- t=null;
- }
- //Display the banner
- public void paint(Graphics g)
- { g.drawString(msg,50,30);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement