Yeah, :D I made it work!
if(e.getKeyCode() == 38)
{
y = player1.getY();
System.out.println("Pressed");
// y = 200;
...
Type: Posts; User: Fermen
Yeah, :D I made it work!
if(e.getKeyCode() == 38)
{
y = player1.getY();
System.out.println("Pressed");
// y = 200;
...
Because the Y value is the components Y - value. When I change the Y value
int y = 100; the component is changing it's position. Then I just thought it sounded reasonable that it would also change...
Because I change the value of y:
y = y + 10;
Or?? wouldn't that work?
I tried using the .setFocusable(true) in "public Spelplan". I also kept the printline "Pressed" inside the if-statement. Now it says "Pressed", but the component does not move.
Why won't my "player1" move???
Class with main
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JPanel;