title: Problem with disappering object on JFrame
body: <p>I have a problem with my program. The rectangle disappears in a certain area on the frame and I have no idea why. I wrote a similar program lately and it worked just fine. The difference was that I draw a circle, not a rectangle.</p>
  <p>Could you please help me find the problem?</p>
  <pre><code>public class Runner {
      
      public static void main(String[] args) {
          AppFrame app = new AppFrame();
          app.setVisible(true);
      }
  }
  </code></pre>
  <hr />
  <pre><code>public class Drawing extends JPanel{
      
      public int getX() {
          return x;
      }
  
      public void setX(int x) {
          this.x = x;
      }
  
      public int getY() {
          return y;
      }
  
      public void setY(int y) {
          this.y = y;
      }
  
      
      private int x;
      private int y;
  
      public void paint(Graphics g) {
          super.paint(g);
          
          Graphics2D g2d = (Graphics2D) g;
          g2d.setColor(Color.RED);
          g2d.fill(new Rectangle2D.Double(x, y, 40, 40));
      }
  
      public void repaintObject() {
          repaint();
      }}
  </code></pre>
  <hr />
  <pre><code>public class AppFrame extends JFrame implements ActionListener {
      
      private int height =600;
      private int width = 600;
      
      private JButton upButton;
      private JButton downButton;
      private JButton rightButton;
      private JButton leftButton;
      
      private JPanel drawingPanel;
      private JPanel buttonsPanel;
      
      private Drawing object;
      private int x;
      private int y;
      
      public AppFrame() {
          
          this.setLayout(new GridLayout(2,1));
          
          drawingPanel= new JPanel();
          buttonsPanel= new JPanel();
          
          drawingPanel.setLayout(new GridLayout(1,1));
          buttonsPanel.setLayout(new BorderLayout());
          
          upButton = new JButton(&quot;Up&quot;);
          downButton = new JButton(&quot;Down&quot;);
          rightButton = new JButton(&quot;Right&quot;);
          leftButton = new JButton(&quot;Left&quot;);
          
          buttonsPanel.add(upButton, BorderLayout.CENTER);
          buttonsPanel.add(downButton, BorderLayout.PAGE_END);
          buttonsPanel.add(rightButton, BorderLayout.LINE_END);
          buttonsPanel.add(leftButton, BorderLayout.LINE_START);
          
          x=100;
          y=100;
          
          object = new Drawing();
          object.setX(x);
          object.setY(y);
          drawingPanel.add(object);
          
          this.add(drawingPanel);
          this.add(buttonsPanel);
          
          upButton.addActionListener(this);
          downButton.addActionListener(this);
          rightButton.addActionListener(this);
          leftButton.addActionListener(this);
      
          this.setSize(height, width);
          
          setLocationRelativeTo(null);
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
          
      }
      
      @Override
      public void actionPerformed(ActionEvent e) {
          Object source = e.getSource();
          
          System.out.println(x+&quot;    &quot;+ y);
          if(source == upButton) {
          
              if(y&gt;=50) {
                  y = y - 50;
                  object.setY(y);
                  object.repaintObject();
              }
              
          } else if(source == downButton) {
              if(y&lt;350) {
                  y = y+50;
                  object.setY(y);
                  object.repaintObject();
              }
          } else if(source == rightButton) {
              if(x&lt;550) {
                  x = x+50;
                  object.setX(x);
                  object.repaintObject();
              }
              
          } else if(source == leftButton) {
              if(x&gt;=50) {
                  x=x-50;
                  object.setX(x);
                  object.repaintObject();
              }
          }   }}
  </code></pre>