Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By JosAH

Thread: problem updating a drawnString

  1. #1
    liluma's Avatar
    liluma is offline Member
    Join Date
    May 2011
    Location
    belgium
    Posts
    50
    Rep Power
    0

    Default problem updating a drawnString

    hey i have made a simple applet wich uses a timer to make a counter rise.

    now all that works good, but the string keeps getting overwritten, so you can't actually read the numbers anymore... >.<

    does anyone know how i can fix this?


    this is the code wich is relevant i think
    Java Code:
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JPanel;
    import javax.swing.Timer;
    
    
    public class Tellerpaneel extends JPanel	
    {
    	private Timer timer;
    	private int teller;
    	
    	public Tellerpaneel()
    	{
    		teller =0;
    		timer = new Timer(100, new TimerHandler());
    		timer.start();
    	}
    	
    	public void paintComponent(Graphics g)
    	{
    		super.paintComponents(g);
    		g.drawString("", 130, 80);
    		g.setColor(Color.BLUE);
    		g.setFont(new Font("SansSerif", Font.BOLD, 14));
    		g.drawString(String.format("Teller = %d",teller), 130,80);
    	}
    	
    	class TimerHandler implements ActionListener
    	{
    		public void actionPerformed(ActionEvent arg0) 
    		{
    			teller++;
    			repaint();
    		}
    	}
    }
    every help is appreciated.:)

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Shouldn't that be:

    Java Code:
    		super.paintComponent(g);
    kind regards,

    Jos
    liluma likes this.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    liluma's Avatar
    liluma is offline Member
    Join Date
    May 2011
    Location
    belgium
    Posts
    50
    Rep Power
    0

    Default

    ty JosAH

    was the problem indeed. :')

    thnks for the help. ^^

  4. #4
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    super.paintComponents(g); != super.paintComponent(g);

    /edit: 2late

Similar Threads

  1. Problem updating access database from jsp
    By Penhexy in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-17-2011, 08:50 AM
  2. Problem with method updating node I don't want it to...
    By sonofshirt in forum New To Java
    Replies: 6
    Last Post: 09-26-2010, 07:14 PM
  3. Problem with updating empty JTable
    By byubi in forum AWT / Swing
    Replies: 1
    Last Post: 05-15-2010, 08:31 AM
  4. Problem with updating JTable
    By kwaspl in forum New To Java
    Replies: 2
    Last Post: 12-20-2009, 10:41 PM
  5. Replies: 0
    Last Post: 04-20-2009, 06:26 PM

Tags for this Thread

Posting Permissions

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