1 Replies - 348 Views - Last Post: 24 November 2012 - 10:34 PM Rate Topic: -----

#1 hwoarang69  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 171
  • Joined: 23-October 12

how to stop japplet from flickering

Posted 24 November 2012 - 10:30 PM

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.JApplet;


public class main extends JApplet implements Runnable
{
	//player information variable
	int x = 10;
	int y = 50;
	int width = 30;
	int height = 30;
	int dx = 1;
	
	//###########################################################################################################
	/*** init method ***/
	public void init()
	{
		setSize(800, 400);
	}/*** end of init method ***/
	
	
	
	//###########################################################################################################
	/*** stat method ***/
	public void start()
	{
		Thread thread = new Thread(this); //set up thread
		thread.start();                   //start thread jump inside run method
	}/*** end of start method ***/
	
	
	//###########################################################################################################
	/*** run method ***/
	public void run()
	{
		
		while(true) //main game loop
		{
			//move image here
			x += dx;
			
			if(x+width >= getWidth())
			{
				x -= dx;
			}
			
			repaint();
			
			try
			{
				Thread.sleep(17);
			}
			catch(InterruptedException e)
			{
				e.printStackTrace();
			}
			
		}//end of while loop
	}/*** end of run method ***/

	
	
	
	//###########################################################################################################
	/*** paint method ***/ 
	public void paint(Graphics g)
	{	
		super.paint(g);
		Graphics2D g2d = (Graphics2D) g; 
		
		
		g.fillRect(x, y, width, height);   //player	
		
	}/** end of paint method ***/
}


Is This A Good Question/Topic? 0
  • +

Replies To: how to stop japplet from flickering

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10667
  • View blog
  • Posts: 39,615
  • Joined: 27-December 08

Re: how to stop japplet from flickering

Posted 24 November 2012 - 10:34 PM

Please avoid duplicate posting.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1