Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

japplet - screen flickers

$
0
0
ok so i think i spend about 3 months on this and having really difficlty with it. I know how to make animation in 'Applet' but when ever i try to make animation in 'JApplet' the screen always flickers. i tried looking on google but it keep giving me result of 'Applet' and not 'JApplet'. i though i should post my code before giving up on japplet animations.

this below code is a really simple animation of a black box moving right on japplet. the box does move right but keep on flickering.

may be some one try running this code on ur computer. bc i have the feeling the problem is in my eclipse.

i have eclipse indigo and runing

name=Eclipse Platform
id=org.eclipse.platform
version=3.7.0

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;
import javax.swing.Timer;



public class main extends JApplet implements ActionListener
{
	//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()
	{
		Timer timer = new Timer(30, this); //set up timer
		timer.start();                   //start timer jump inside actionperformed method
	}/*** end of start method ***/
	
	
	//###########################################################################################################
	/*** game loop ***/
	public void actionPerformed(ActionEvent e)
	{
		//move image here
		x += dx;
		
		if(x+width >= getWidth())
		{
			x -= dx;
		}
			
		repaint();
	}/*** end of run method ***/

	
	
	
	//###########################################################################################################
	/*** paint method ***/ 
	public void paint(Graphics g)
	{	
		super.paint(g); //redraw paint method. so it doesnt draw on top of each other
		
		g.fillRect(x, y, width, height);   //player	
	}/** end of paint method ***/
}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>