Java code for a SImple Java Banner Applet!
SLVIKI
8:12 PM
0
This is the java code of the simple java banner applet.
/* Project 14-1 A simple 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="Banner" width=300 height=50> </applet> */ public class Banner extends Applet implements Runnable { String msg = "This is the moving text of this java Banner applet! "; Thread t; boolean stopFlag; // Initialize t to null public void init() { t = null; } // Start 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()); msg += ch; if(stopFlag) break; } catch (InterruptedException exc) {} } } // Pause the banner public void stop() { stopFlag = true; t = null; } // Display the banner. public void paint(Graphics g) { g.drawString(msg, 50, 30); } }
Here is the sample output of this program.
Enjoy! if you have any questions fell free to ask!
No comments