title: (JAVA) moving clipping area by keylistener
body: <p>My goal is moving clipping area 10 pixels at a time using arrow keys. I got the image on the panel and the clipping area is there too, but the thing is that the clipping area won't move. Here is my code, and I hope to learn what's wrong with it.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  public class clipping_area extends JFrame{
      clipping_area(){
          setTitle("OpenChallenge");
          setVisible(true);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setSize(500,500);
          add(new panelOC());
      }
      class panelOC extends JPanel{
          int xAxis=0;
          int yAxis=0;
          public void paintComponent(Graphics g){
              super.paintComponent(g);
              Image img=(new ImageIcon("images/image1.jpg")).getImage();
              g.setClip(100+10*xAxis,100+10*yAxis,50,50);
              g.drawImage(img,0,0,getWidth(),getHeight(),this);
          }
          panelOC(){
              requestFocus();
              addKeyListener(new KeyAdapter(){
                  public void keyPressed(KeyEvent KE){
                      if(KE.getKeyCode()==KeyEvent.VK_UP){
                          yAxis-=1;
                          repaint();
                      }
                      else if(KE.getKeyCode()==KeyEvent.VK_DOWN){
                          yAxis+=1;
                          repaint();
                      }
                      else if(KE.getKeyCode()==KeyEvent.VK_LEFT){
                          xAxis-=1;
                          repaint();
                      }
                      else if(KE.getKeyCode()==KeyEvent.VK_RIGHT){
                          xAxis+=1;
                          repaint();
                      }
                  }
              });
          }
      }
      public static void main(String[] args){
          new clipping_area();
      }
  }
  </code></pre>