title: How I can move the shape left,right,up,down in java swing
body: <p>I am trying to move shape with button , but I am not getting it. This is my draw class </p>
  
  <pre><code>class MyCanvas extends JComponent {
  
  
        public void paint(Graphics g) {
  
          g.setColor(Color.RED);
          g.fill3DRect(20, 20, 200, 200,true);
        }
  
      }
   class MyCanvas1 extends JComponent {
  
  
        public void paint(Graphics g) {
  
          g.setColor(Color.RED);
          g.drawRect(20, 20, 200, 200);
        }
      }
  </code></pre>
  
  <p>I done drawing successfully by below code -- ></p>
  
  <pre><code>public class ButtonListener implements ActionListener
    {
  
  
  
      public void actionPerformed(ActionEvent e) {
          if(check)
          {
  
              if(e.getSource()==btnNewButton)
              {
                  MyCanvas can=new MyCanvas();
                  me s=new me();
                  can.setSize(400, 500);
                  panel_3.add(can);
                  panel_3.repaint();
                  addComponent(can);
                  s.can;
                  choice=true;
  
              }
         }
        else
        {
         if(e.getSource()==btnNewButton)
              {
                  panel_3.removeAll();
                  MyCanvas1 can=new MyCanvas1();
                  can.setSize(500, 500);
                  panel_3.add(can);
                  panel_3.repaint();
                  addComponent(can);
              }
         }
  </code></pre>
  
  <p>Its working fine for me. Now I have another 4 button and I want to move the shape by click on button. I try few method but none of them working for me. Any suggestion how I can do it.Should I create any new action event or class.</p>