Results 1 to 29 of 29

Thread: How would you do this?

Threaded View

  1. #29
    Junior Member lemenz70's Avatar
    Join Date
    Apr 2005
    Location
    Canada (Quebec)
    Posts
    23

    Re: How would you do this?

    where am I supposed to add the revalidate or repaint in this class?

    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();
     	}
     }
    thanks

    Edit: Fixed! I had to add a revalidate there:
    Code:
     public void actionPerformed(ActionEvent e) {
         /**
          * Force a Repaint.
          */
         this.repaint();
         this.revalidate();
       }
    I finally made it thanks for your help!
    Last edited by lemenz70; Apr 18th, 2005 at 06:23 PM.
    William

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width