Moving Banner in Java

satheesh

New Member
Messages
883
Reaction score
0
Points
0
Code for java:

Code:
/*
 * MovingBanner.java
 *
 * Created on October 29, 2007, 7:16 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package satheesh;
import java.awt.*;
import java.applet.*;
/**
 *
 * @author Administrator
 */
public class MovingBanner extends Applet implements Runnable {
String msg;
Thread t=null;
int state;
boolean stopflag;

    public void init() 
    {
    setBackground(Color.BLACK);
    setForeground(Color.WHITE);
    }
    
     public void start() {
        msg=getParameter("msg");
        t = new Thread(this);
        stopflag=false;
        t.start();
    }
     
    public void run(){
        char ch;
        for(;;){
            try{      
            repaint();
            Thread.sleep(250);
            ch=msg.charAt(0);
            msg=msg.substring(1,msg.length());
            msg+=ch;
            if(stopflag){
                break;
            }
            }catch(InterruptedException e){
                System.out.print("Error:"+e);
            }
        }
    }
    public void stop(){
        stopflag=true;
        t=null;
    }
    
    public void paint(Graphics g)
    {
        g.drawString(msg,10,30);        
    }
    
}

/*
<P>
<APPLET codebase="./" code="MovingBanner.class" width=150 height=50><param name="msg" value="-Free Hosting By x10hosting.com-">
</APPLET>
</P>
*/

Save as MovingBanner.java and Compile and run it.

Demo:http://svprm.x10hosting.com/java/MovingBanner.html
 

Sohail

Active Member
Messages
3,055
Reaction score
0
Points
36
Nice tutorial! But try not to double post the thread next time. :)
 

Akisboy32

New Member
Messages
25
Reaction score
0
Points
0
Hmm..are you sure your not forgetting some files like Applet.java and so??...
Plus , this cannot be called as a "Tutorial", Why? - because it does not explain/teach anything to anybody , you just put the code and disappear.
Explain more about the methods you have used, and if you can provide links for the sun.java tutorials about the "if" statement and so.
 
Last edited:

EagleEye

New Member
Messages
2
Reaction score
0
Points
0
i cant figure out how to post the x10hosting ad on my page as it looks like its javascript.
 
Top