title: Move a BALL on Jpanel with keyboard down key
body: <p>I have a class mypanel extends from jpanel where i use the graphics and make a ball. Second class is Main where  i make a JFrame and add panel to frame. There is another class  MKeyListener in Main which extends from KeyAdapter  class where i handel the keyboard event.   I have made a object of Jpanel class in Main class and register the MkeyListener class with the jpanel class.  now i want to move down the ball on jpanel  with down keyboard key butt ball is not moving down with down key that is code of my programe.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  class mypanel extends JPanel{
       int n=0;
       int m=0;
       int i=170;
       int j=340;
       int a=60;
       int b=20;
      public void paintComponent (Graphics g){
          super.paintComponent(g);
          Graphics2D g2= (Graphics2D)g;
          g2.setColor(Color.green);
          g2.fillOval(n,m,10,10);
      }
  }
  
  public class Main {
      JFrame frame;
      mypanel p;
      int x,y;
      public Main (){
      x=0;
      y=0;    
       frame=new JFrame();
      Container c = frame.getContentPane();
      c.setLayout(new BorderLayout());
      p = new mypanel();
      c.add(p,BorderLayout.CENTER);
      frame.setSize(400,400);
      frame.setVisible(true);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      MKeyListener k=new MKeyListener();
      p.addKeyListener(k);
  
      }
  
      public static void main(String args []) {
          Main a= new Main();
      }
  
  
  class MKeyListener extends KeyAdapter {
  
      public void keyPressed(KeyEvent event) {
  
    if (event.getKeyCode()==KeyEvent.VK_DOWN ) {
        x =x+4;
              y=y+4;
           p.n+=x;
           p.m+=y;
           p.repaint();
     System.out.println("success");
    }
      }
  }
  
  }
  </code></pre>