Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • October 28, 2016, 09:09:23 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Simple Java timer lag issue (caused by quad core?)  (Read 2626 times)


  • Honorary Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 93
    • View Profile
    • AppAholic
    • Donate to Member
Simple Java timer lag issue (caused by quad core?)
« on: December 14, 2008, 04:59:18 PM »
Hi everyone.
I've just finished my first term at uni, and learnt some java.
I'm creating a simple helicopter game in java, and have some issues using timers.
The funny thing was, i started the project on my laptop, and it was going fine. Went back to my desktop, and it lagged. Weird. So I tried it on my laptop again, and it had no lag.
By lag, I mean graphically and mouse movement when the application runs. Its not consuming resources, so that's not the problem.
I read something on a forum about it being to do with the fact my desktop has a quad core. If this is the case, how can I work around this? Obviously I will have to use my laptop for now. Laptop is dual core running vista, desktop is a quad core running xp sp3.
code listing below. 2 separate files but together for this forum

import javax.swing.JFrame;
import java.awt.*;

public class HeliApp extends Object
   public static void main(String[] argStrings) throws Exception
      JFrame frame = new JFrame ("Heli");
      frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
      frame.getContentPane().add (new HeliPanel());   

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*

public class HeliPanel extends JPanel
   int heliX = 50;
   int heliY = 200;
   int yMove = 5;
   private ImageIcon image;
   int delay = 20;
   private Timer timer;
   public HeliPanel()
      image = new ImageIcon ("../black-helicopter.gif");
      setBackground (Color.white);
      setPreferredSize (new Dimension(1000,400));
      setFocusable (true);
      Timer timer = new Timer(10, new GameListener());
   public void paintComponent (Graphics page)
      super.paintComponent (page);
      image.paintIcon (this,page,heliX, heliY);
   private class GameListener implements ActionListener
      public void actionPerformed (ActionEvent event)
         heliY = heliY + yMove;
<a href="http://feeds.feedbur...om/~r/Appaholic/~6/3"><img src="http://feeds.feedbur....com/Appaholic.3.gif" alt="Are You An AppAholic?" style="border:0"></a>