Hi.
I am working on a simple arcade game in Java.
I know C++, and some Java, and I also have a basic understanding of Swing and AWT, and I would like some advice on how to use animation in swing.
As I understand it, I shouldn’t use the EDT for drawing, but should use an external thread and have it call repaint() every so often, but I have been having some problems with doing that.
The animation seems pretty smooth, but the JPanel that my game is contained in isn’t catching most of my mouseEvents, I believe this may be because I am somehow causing problems with the EDT.
Here is the pseudocode of my game:
public class MyGame extends JPanel implements Runnable {
public MyGame {
addMouseListener(new L);
}
run() {
doInput();
doAI();
repaint();
Thread.sleep(100);
}
public void paint(Graphics g) {
super.paint();
paintThings(g);
}
private class L extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
//register input
}
}
}
I am sure this has already been covered, if it has, can someone please point me to a good tutorial on this kind of thing?