title: JProgressBar without JButton and PropertyChangeListener
body: <p>I am new to <code>JProgressBar</code> and new to OOPs concepts as well (learning it) and read a lot of articles and tried my best to learn it. All of the examples shown had a button which starts progress in it but how can I make a method so that when the method is called it starts progress?</p>
  
  <p>Here is my code first</p>
  
  <pre><code>import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.JProgressBar;
  import javax.swing.SwingWorker;
  
  public class ProgressDemo
  {
      JProgressBar ProgressBar;
      Task task;
      boolean done = false;
  
      class Task extends SwingWorker&lt;Void, Void&gt; 
      {
          @Override
          public Void doInBackground() 
          {
              Random random = new Random();
              int progress = 0;
              setProgress(0);
              while (progress &lt; 100) 
              {
                 try 
                 {
                      Thread.sleep(random.nextInt(1000));
                 } 
                 catch (InterruptedException ignore){}
                 progress += random.nextInt(10);
                 setProgress(Math.min(progress, 100));
              }
              return null;
          }
          @Override
          public void done() 
          {
              done = true;
          }
      }
  
      public void propertyChange(PropertyChangeEvent evt) 
      {
        if(!done)
        {
          int progress = task.getProgress();
          if(progress==0)
          {
              ProgressBar.setIndeterminate(true);
          }
          else
          {
              ProgressBar.setIndeterminate(false); 
              ProgressBar.setString(null);
              ProgressBar.setValue(progress);
          }
        }
      }
  
      //I want to make a method here, so that it can be called when ever I want
      public void ExecuteTask()
      {
          task = new Task();
          task.execute();
      }
  
      public static void main(String[] args) 
      {
          JFrame MainScreen = new JFrame(); 
          JPanel MainPanel = new JPanel();
          ProgressBar = new JProgressBar(0, 100);
          ProgressBar.setValue(0);
          ProgressBar.setStringPainted(false);
          MainPanel.add(ProgressBar);
          MainScreen.getContentPane().add(MainPanel);
          MainScreen.setVisible(true);
      }
  }
  </code></pre>
  
  <p>My <code>jProgressBar</code> is not listening when I call <strong>ExecuteTask()</strong> method. How can I make it to call <strong>ExecuteTask()</strong> and it execute task and jProgressBar listen to it?</p>