Hi everyone.
I'm new to this forum, recommended by a friend.
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());
frame.pack();
frame.setVisible(true);
}
}
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());
timer.start();
}
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;
repaint();
}
}
}