Results 1 to 6 of 6
  1. #1
    poorbrain is offline Member
    Join Date
    Mar 2011
    Posts
    10
    Rep Power
    0

    Default Switch Case with Repaint Flcikers

    I am very new to applets. I was wondering if anyone can help me with this. This applet takes user input as a single number digit on the button click, then draws it in rectangular form. But it keeps flickering when using repaint(). I'm not sure if there is a way to clear the whole applet then repaint this or what other methods would do this correctly. any help would be appreciated.
    Last edited by poorbrain; 03-03-2011 at 03:44 AM.

  2. #2
    NRitH is offline Senior Member
    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    0

    Default

    Why are you calling repaint() *before* filling your rects? You shouldn't need to call it at all.

  3. #3
    poorbrain is offline Member
    Join Date
    Mar 2011
    Posts
    10
    Rep Power
    0

    Default

    if I take out repaint, it just stays at the default rectangle shape. Or if i put it at the end of the switch case before the break statement it does the same thing, just stays digit of 0 even if I change it to any other digit.

  4. #4
    poorbrain is offline Member
    Join Date
    Mar 2011
    Posts
    10
    Rep Power
    0

    Default

    correction, if i take it out it wont change but if i put it at the end it does the same thing and flickers

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Agree having repaint inside of a paint method is simply crazy. Of course this thing will flicker to death. Wouldn't it be much smarter to call repaint in the actionPerformed method, after updating num?

    Better still is to do all of your drawing in the paintComponent method of a JPanel, not the paint method of a JApplet.

  6. #6
    poorbrain is offline Member
    Join Date
    Mar 2011
    Posts
    10
    Rep Power
    0

    Default

    eh, I thought I already tried putting repaint in the actionPerformed method.......

    eh i guess not... works now fine. thanks a lot for the help I really appreciate it, been messing around with changing the code around and google searching for about a hour or two. then remembered these kind of forums had helped me out before.

    I hate stupid simple fixes like this, spend all this time for something so simple. has happened to me many times before.

Similar Threads

  1. Converting if to Switch Case.
    By king2be98 in forum New To Java
    Replies: 5
    Last Post: 02-20-2011, 04:46 PM
  2. Switch Case statement
    By seanfmglobal in forum New To Java
    Replies: 7
    Last Post: 02-15-2011, 02:18 PM
  3. if else changes to switch-case?
    By noobinoo in forum New To Java
    Replies: 1
    Last Post: 04-23-2010, 06:56 PM
  4. Replies: 2
    Last Post: 02-23-2009, 01:34 AM
  5. Switch Case and Key Events
    By AndrewM16921 in forum New To Java
    Replies: 4
    Last Post: 01-27-2009, 12:20 AM

Posting Permissions

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