title: Update JFrame paintings
body: <p>I want to update my rectangle when my key is pressed currently I have almost achieved that</p>
  
  <pre><code>package com.raggaer.frame;
  
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Graphics;
  
  import javax.swing.JPanel;
  import javax.swing.KeyStroke;
  
  public class Elements extends JPanel {
  
      private static int y = 250;
  
      public Elements() {
  
          this.getInputMap().put(KeyStroke.getKeyStroke("UP"), "up");
          this.getActionMap().put("up", new Listener("up"));
          this.getInputMap().put(KeyStroke.getKeyStroke("DOWN"), "down");
          this.getActionMap().put("down", new Listener("down"));
      }
  
      public void paintComponent(Graphics g) {
  
          super.paintComponent(g);
  
          g.drawRect(250, this.y, 10, 10);
      }
  
      public Dimension getPreferredSize() {
  
          return new Dimension(500, 500);
      }
  
      public static void setY(int cord) {
  
          y += cord;
              // Cant access repaint()
      }
  }
  </code></pre>
  
  <p>And this is my listener class</p>
  
  <pre><code>package com.raggaer.frame;
  
  import java.awt.Graphics;
  import java.awt.event.ActionEvent;
  import java.awt.event.KeyEvent;
  import java.awt.event.KeyListener;
  
  import javax.swing.AbstractAction;
  
  public class Listener extends AbstractAction {
  
      private String code;
  
      //final Elements game = new Elements();
  
      public Listener(String order) {
  
          this.code = order;
      }
  
      public void actionPerformed(ActionEvent e) {
  
          System.out.println(this.code);
  
          Elements.setY(1);
      }
  }
  </code></pre>
  
  <p>Currently everything works except that I dont know how to update the y position of the rectangle, I tried using an static variable but then I cant call the repaint() method.</p>