title: Why my JPanel is not painting anything after I changed the design to same class
body: <p>I am writing a code to draw some shapes on a JPanel. I have now shifted the paint method from a different class to same class. But, now suddenly my JPanel is coming as blank. Do you guys know why is it happening? Moreover, If i want to repaint it again after changing x=x+5. How can I repaint this?</p>
  
  <p>Code:</p>
  
  <pre><code>import java.awt.*;
  import java.util.*;
  import javax.swing.*;
  
  @SuppressWarnings("serial")
  public class Filter extends JFrame {
  
        public static void main(String[] args)
        {
              SwingUtilities.invokeLater(new Runnable()
              {  
                  public void run() 
                  {
                      Filter mainFrame = new Filter();
                      mainFrame.setVisible(true);
                  }
              });
        }
  
      public Filter()
      {
          //Creating the JFrame main window
          setSize(800, 500);
          setTitle("Particle Filter");
          setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          setLocation(100, 100);
          getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.X_AXIS));
          setResizable(false);
  
          //creates two panels content and sidebar. Sidebar has null layout       
          JPanel content = new JPanel();
          content.setPreferredSize(new Dimension(700,500));
          content.setBackground(Color.LIGHT_GRAY);
          this.getContentPane().add(content);
          JPanel sidebar = new JPanel();
          sidebar.setBackground(Color.LIGHT_GRAY);
          sidebar.setPreferredSize(new Dimension(100,500));
          this.getContentPane().add(sidebar);
          sidebar.setLayout(null);
  
          //creates three buttons in sidebar
          JButton start_button = new JButton("START");
          start_button.setBounds(10, 75, 77, 23);
          sidebar.add(start_button);
          JButton stop_button = new JButton("STOP");
          stop_button.setBounds(10, 109, 77, 23);
          sidebar.add(stop_button);
          JButton reset_button = new JButton("RESET");
          reset_button.setBounds(10, 381, 77, 23);
          sidebar.add(reset_button);
  
          //Creates the main_content Panel, the number of particles and calls the drawShapes function
          JPanel main_content = new JPanel();
          main_content.setPreferredSize(new Dimension(680,450));
          main_content.setBackground(Color.WHITE);
          content.add(main_content);
          main_content.repaint();
  
      }
  
      public void paintComponent(Graphics g)
      {
          int n=1000; // n denotes the number of particles
  
          ArrayList&lt;Integer&gt; list;        
          list = new ArrayList&lt;Integer&gt;(Collections.nCopies(n, 0));
  
          createObstacles(g,150,225,100,40);
          createObstacles(g,500,300,40,100);
  
          for(int i=0;i&lt;list.size();i++)
          {
             generateParticles(g);
          }
  
          int x=0, y=0;     
          //creates a robot randomly in the JPanel without overlapping on the two obstacle rectangles
          int robot_radius=50;
          ArrayList&lt;Integer&gt; robot_list= new ArrayList&lt;Integer&gt;();
          list=positionRobot(x,y);
          drawRobot(g,robot_list.get(0),robot_list.get(1),robot_radius);
      }
  
      private void generateParticles(Graphics g)
      {
          int x=0;
          int y=0;
          int radius = 4;
          ArrayList&lt;Integer&gt; list= new ArrayList&lt;Integer&gt;();
          list=positionParticles(x,y);
          g.setColor(Color.RED);
          g.fillOval(list.get(0),list.get(1), radius, radius);
      }
  
      private ArrayList&lt;Integer&gt; positionParticles(int x, int y)
      {
          int radius = 4;
          ArrayList&lt;Integer&gt; list= new ArrayList&lt;Integer&gt;();
          x=randomInteger(2,678); // bounds of x between which the particles should be generated
          y=randomInteger(2,448); // bounds of y between which the particles should be generated
          x=x-(radius/2);
          y=y-(radius/2);
          if((x&lt;251&amp;&amp;x&gt;=150)&amp;&amp;(y&lt;266&amp;&amp;y&gt;=225))
          {
              x=0;
              y=0;
              positionParticles(x,y);
          }
          if((x&lt;541&amp;&amp;x&gt;499)&amp;&amp;(y&lt;401&amp;&amp;y&gt;299))
          {
              x=0;
              y=0;
              positionParticles(x,y);
          }
          list.add(x);
          list.add(y);
          return list;
      }
  
      private ArrayList&lt;Integer&gt; positionRobot(int x, int y)
      {
          int robot_radius=50;   
          ArrayList&lt;Integer&gt; list= new ArrayList&lt;Integer&gt;();
          x=randomInteger(25,655);//so that it stays inside the content_Walls panel 
          y=randomInteger(25,425); //so that it stays inside the content_Walls panel 
          x=x-(robot_radius/2);
          y=y-(robot_radius/2);
          if((x&lt;250&amp;&amp;x&gt;=150)||(y&lt;=265&amp;&amp;y&gt;=225))
          {
             x=0;
             y=0;
             positionRobot(x,y);
          }
          if((x&lt;=540&amp;&amp;x&gt;=500)||(y&lt;=400&amp;&amp;y&gt;=300))
          {
              x=0;
              y=0;
              positionRobot(x,y);
          }
          list.add(x);
          list.add(y);
          return list;            
      }
  
      private void createObstacles(Graphics g, int x, int y, int width, int height)
      {
          g.setColor(Color.BLACK);
          g.fillRect(x, y, width, height);
      }
  
      private void drawRobot(Graphics g, int x, int y, int radius)
      {
          g.setColor(Color.GREEN);
          g.fillOval(x, y, radius, radius);   
      }
  
      private static int randomInteger(int min, int max)
      {
          Random rand = new Random();
          int randomNum = rand.nextInt((max - min) + 1) + min;
          return randomNum;
      }
  }
  </code></pre>