Hi
Very slowly trying to learn java, reading from a book and it gave me the following example for a simple scrolling banner.
Used in :Code:import java.awt.*; import java.applet.*; /* <applet code="AppletBanner.class" width=300 height=50> </applet> */ public class AppletBanner extends Applet implements Runnable { String msg = " A Simple Moving Banner."; Thread t = null; int state; volatile boolean stopFlag; //called first public void init() { // init setBackground(Color.cyan); setForeground(Color.red); } public void start() { t = new Thread(this); stopFlag = false; t.start(); } public void stop() { stopFlag = true; t = null; } public void run() { for( ; ; ) { try { repaint(); Thread.sleep(250); if(stopFlag) break; } catch (InterruptedException e) {} } } public void paint(Graphics g) { char ch; ch= msg.charAt(0); msg = msg.substring(1, msg.length()); msg += msg + ch; g.drawString(msg, 50, 30); } }
When I run through appletviewer, it initially opens, although sizes don't correspond... But the applet viewer allows me to stretch the window. Which I did. At this point it all went wrong. The text was repainted more than once and well over the limits given.Code:<html> <p> This file launches the 'A' applet: A.class! </p> <!-- <applet code="AppletSkel.class" height=200 width=320> --> <applet code="AppletBanner.class" height=400 width=400> No Java?! </applet> </html>
So my question:
If I ran this on a web server, would it work fine as the applet is sized on html?
---> or like the appletviewer would it run for two seconds then crash with a long list of errors including no memory...?




Reply With Quote