I've added the looping... the image thing is easy enough, i just don't have an image handy to try out, but you can see where i'd add it...
Code:import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JComponent; import javax.swing.Timer; /** * @author ad */ public class ScrollingTextComponent extends JComponent implements ActionListener{ private String[] text; private Timer t; int start = 80; private boolean firstTime = true; /** * Create a new Scrolling Text Component * Either Up for Left. */ public ScrollingTextComponent(String[] text) { this.text = text; this.t = new Timer(20, this); this.t.start(); } /** * paint * @see javax.swing.JComponent#paint(java.awt.Graphics) */ public void paint(Graphics g) { if(this.firstTime) { this.start = g.getClipBounds().height; this.firstTime = false; } FontMetrics fm = g.getFontMetrics(); int yLocation = this.start + fm.getHeight(); int stopCount = 0; for(int i = 0; i < this.text.length; i++) { if(yLocation > 0) { g.drawString(this.text[i], 0, yLocation); }else { stopCount++; } yLocation += + fm.getHeight(); } //g.drawImage(this.image, 0, y, null); if(stopCount == this.text.length){ this.start = g.getClipBounds().height; } this.start--; } /** * actionPerformed * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { /** * Force a Repaint. */ this.repaint(); } }




Reply With Quote