import java.applet.*; // involve applet packages
import java.awt.*;
public class Marquee extends Applet {
private Image buffer; // buffer and bufferg are
private Graphics bufferg; // used for double fuffering
private int width; // applet's wodth
private int height; // applet's height
private String text; // text for scrolling
private int x; // aux variable
public void init() { // initialization
text = getParameter("text"); // get text
setBackground(new Color(230,230,130)); // set bgcolor
width = getSize().width; // get applet's width
height = getSize().height; // set applet's height
buffer = createImage(width, height); // create buffers
bufferg = buffer.getGraphics(); // for double buffering
x = width;
}
public void update(Graphics g) { //overwrites standard update
paint(g);
}
public void paint(Graphics g) { // all applet output is here
bufferg.setColor(getBackground()); // set bgcolor
bufferg.fillRect(0, 0, width, height); // clean off-screen buffer
bufferg.setColor(Color.red); // set text color
bufferg.drawString(text, x, 10); // draw text at (x, y)
g.drawImage(buffer, 0, 0, this); // swap the buffers
if (x < -bufferg.getFontMetrics().stringWidth(text))
x = width; // next string position
else // for drawing
x = x - 1;
try {Thread.sleep(30);} // start animation
catch(InterruptedException e){}
repaint(); // update the buffers
}
}
Tuesday, 30 April 2013
buffring marquee
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment