Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: my Button is flickering

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default my Button is flickering

    why is that when I put the button on a while statement with other method such as the paint() and the fullscreen method with update.

    public void gameLoop(){
    		long startTime = System.currentTimeMillis() ;
    		long Time = startTime;
     
    		while (running){
    			Window w = s.getFullScreenWindow();
    			long timePassed = System.currentTimeMillis() - Time;
    			Time += timePassed;
     
    			if(pause){		
    			updateHeartPosition();
    			updateEverything(timePassed);	
     
    			actionPerformed();
     
     
    			Graphics2D g = s.getGraphics();	
    			draw(g);
     
    			g.dispose();
     
    			s.update();
    			}
     
    			if(!pause){
    				Window w2 = s.getFullScreenWindow();
    				Graphics2D g = s.getGraphics();
    				drawOption(g);
    				g.dispose();
    				s.update();
    				option = new JButton("Rod");
    				option.setBounds(0, 0, 200, 200);
    				w2.add(option);
    			}
    			try{
    				Thread.sleep(20);
    				}catch(Exception ex){
     
    				}
     
     
    		}//for game loop
     
     
     
    	}


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,110
    Thanks
    65
    Thanked 2,717 Times in 2,667 Posts

    Default Re: my Button is flickering

    Please make a small complete program that compiles, executes and shows the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: my Button is flickering

    You don't mix creating components with drawing, and in fact your drawing code should be lean, mean, and blindingly fast and not have to worry itself with program logic or component creation or removal. Usually we use passive graphics where we do our drawing in a JComponent's (or JComponent-derived component's) paintComponent(...) method. You appear to be trying to use "active" rendering which has issues of its own. Are you sure that this is the route you wish to take? Are you following a tutorial that is directing you to take this route?

Similar Threads

  1. Screen is flippering / flickering.
    By Ulixava in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 5th, 2012, 01:54 PM
  2. Double buffered Image is flickering
    By jay-wo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 29th, 2011, 11:21 PM
  3. JPanel flickering
    By Ghosth in forum AWT / Java Swing
    Replies: 1
    Last Post: April 30th, 2011, 10:52 AM
  4. Java swing buttons are flickering in windows 7 environment
    By javasam in forum Member Introductions
    Replies: 1
    Last Post: February 17th, 2011, 09:51 AM
  5. Java swing buttons are flickering in windows 7 environment
    By javasam in forum AWT / Java Swing
    Replies: 1
    Last Post: February 14th, 2011, 12:13 PM