hey im trying to make a simple ascii game in java but i cant get the graphics to update on key presses
im trying to make it so the guy is controllable with the arrow keys
heres the code
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.Timer;
public class shooter extends JFrame{
int x = 100, y = 100, dx, dy;
Timer time;
/**
*
*/
private static final long serialVersionUID = 1L;
public void move(){
x = x + dx;
y = y + dx;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public shooter() {
setTitle("title of gip");
setSize(600, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
//keep at bottom
setVisible(true);
//dont code here >:(
}
///////////GRAPHICS ////////////////////
public void paint(Graphics g){
g.clearRect(0, 0, getWidth(), getHeight());
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.white);
g.drawString("☺", getX(), getY());
}
public void paintComponent(Graphics g){
}
//////////////end of graphics//////////////
public void keyPressed(KeyEvent e){
int pressed = e.getKeyCode();
if (pressed == KeyEvent.VK_LEFT){
dx = -1;
}
if (pressed == KeyEvent.VK_RIGHT){
dx = 1;
}
}
public void keyReleased(KeyEvent e){
int rel = e.getKeyCode();
if (rel == KeyEvent.VK_LEFT){
dx = 0;
}
if (rel == KeyEvent.VK_RIGHT){
dx = 0;
}
}
public void actionPerformed(ActionEvent e) {
move();
repaint();
}
public static void main(String[] args){
new shooter();
}
}
please help thanks