Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. /* A sample banner applet.
  2.  
  3. This applet creates a thread that scrolls
  4. the message contained in msg right to left
  5. across the applet's window.
  6. */
  7.  
  8. import java.awt.*;
  9. import java.applet.*;
  10.  
  11. /* <applet code="SampleAppletBanner" width=300 height=100>
  12. </applet>
  13. */
  14.  
  15. public class SampleAppletBanner extends Applet implements Runnable
  16. { String msg="A sample moving banner";
  17. Thread t=null;
  18. int state;
  19. boolean stopFlag;
  20.  
  21. // Set colors and intialize thread
  22. public void start()
  23. { t=new Thread(this);
  24. stopFlag=false;
  25. t.start();
  26. }
  27.  
  28. // Entry point for the thread that runs the banner
  29. public void run()
  30. { char ch;
  31.  
  32. // Display banner
  33. for( ; ;)
  34. { try
  35. { repaint();
  36. Thread.sleep(250);
  37. ch=msg.charAt(0);
  38. msg=msg.substring(1,msg.length());
  39. if(stopFlag)
  40. break;
  41. }
  42. catch(InterruptedException e)
  43. {}
  44. }
  45. }
  46.  
  47. // Pause the banner
  48. public void stop()
  49. { stopFlag=true;
  50. t=null;
  51. }
  52.  
  53. //Display the banner
  54. public void paint(Graphics g)
  55. { g.drawString(msg,50,30);
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement