Well, after searching through this forum and practically the entire net, I figured out how to do graphics and KeyInput inside of a JFrame. Unfortunantely, the speed at which I recieve keyboard input is unaceptable for a game. I figured that the initial delay is due to the OS’s repeat delay for the keyboard (under control panel for windows). Well, what I’m asking is if there is some way to ignore the repeat delay or query the keybuffer directly, any help on this would be greatly appreciated.
code:
`import java.awt.;
import java.awt.event.;
import javax.swing.JFrame;
public class Pong extends Canvas {
private int lastX;
private int lastY;
private Graphics context;
public static void main(String args[]) {
JFrame frame = new JFrame("Pong");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(0,0,500,500);
frame.setVisible(true);
frame.getContentPane().add(new Pong(500, 500));
}
public Pong ( int width, int height) {
super();
this.setSize( width, height);
this. enableEvents( AWTEvent.MOUSE_MOTION_EVENT_MASK |
AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.KEY_EVENT_MASK);
}
public void addNotify() {
super.addNotify();
context = this.getGraphics().create();
}
public void processKeyEvent(KeyEvent event) {
System.out.println(event.getID());
}
public void processMouseMotionEvent(MouseEvent event) {
if ( event.getID() == MouseEvent.MOUSE_DRAGGED) {
int currentX = event.getX();
int currentY = event.getY();
context.drawLine( lastX, lastY, currentX, currentY);
lastX = currentX;
lastY = currentY;
}
}
}`
Thanks!
ps. I’m sorry if this is the wrong forum to post in, but I couldn’t find a better one, and this is kinda about 2d graphics