I want the button to move left, right, up, and down after typing a number on the jtext field. This is the code that I have right now
private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {
int keyCode = evt.getKeyCode();
int x = jButton1.getLocation().x;
int y = jButton1.getLocation().y;
switch(keyCode)
{
case KeyEvent.VK_UP:
jButton1.setLocation(x,y-50);
break;
case KeyEvent.VK_DOWN:
jButton1.setLocation(x,y+50);
break;
case KeyEvent.VK_LEFT:
jButton1.setLocation(x-50,y);
break;
case KeyEvent.VK_RIGHT:
jButton1.setLocation(x+50,y);
break;
}
}