3 Replies - 247 Views - Last Post: 14 January 2013 - 12:15 AM Rate Topic: -----

#1 hwoarang69  Icon User is offline

  • D.I.C Head

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

japplet - screen flickers

Posted 13 January 2013 - 10:52 PM

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 ***/
}

This post has been edited by hwoarang69: 13 January 2013 - 10:57 PM


Is This A Good Question/Topic? 0
  • +

Replies To: japplet - screen flickers

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10466
  • View blog
  • Posts: 38,786
  • Joined: 27-December 08

Re: japplet - screen flickers

Posted 13 January 2013 - 10:59 PM

I ran your code and didn't encounter a flicker. It may be specific to your system.
Was This Post Helpful? 1
  • +
  • -

#3 hwoarang69  Icon User is offline

  • D.I.C Head

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

Re: japplet - screen flickers

Posted 14 January 2013 - 12:13 AM

by any change u have a idea what could it be? i am using window 7 on Mac laptop. could that be a graphic problem.

but applet animation works fine so i guess its my eclipse .
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10466
  • View blog
  • Posts: 38,786
  • Joined: 27-December 08

Re: japplet - screen flickers

Posted 14 January 2013 - 12:15 AM

If you're encountering a flicker, your refresh rate may be too high. You could try adding a few extra milliseconds to the Timer delay.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1