Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: SwingWorker class, the process method

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default SwingWorker class, the process method

    I'm currently experimenting with the SwingWorker class.
    I've created a Swingworker Class:

    class DownloadWorker extends SwingWorker<Integer, Integer> {

    In this class I've overriden the following methods:
    @Override
    protected Integer doInBackground() throws Exception {

    and
    @Override
      protected void done() {

    However my problem came with the publish and process methods.
    I've looked into many online articles but I just cannot fully understand these two methods and ther cooperation.
    I've added the following code (just for the sake of the example) in the doInBackground method:

    @Override
    protected Integer doInBackground() throws Exception {
      for (int i=0; i<10000; i++) {
        publish(i);
      }
    }

    When I add the following in the downloadWorker class:
    protected void process( int a) {
        System.out.println("process method!: a = " + a);
      }
    There are no errors but the process method is never executed.
    So I went looking further for a solution and came up with the following:
     protected void process( java.util.List<Object> chunks) {
     
      }
    I work in netbeans 7.0.1 and netbeans gives me the following error: "name clash: process(java.util.List<java.lang.Object>) in download.DownloadWorker and process(java.util.List<V>) in javax.swing.SwingWorker have the same erasure, yet neither overrides the other"

    So My next thought was to add an @Override notation.
    The moment I do that it gives me the following error:"method does not override or implement a method from a supertype"

    At this point I'm really confused and I've got no clue how the process methods works.
    If somebody could please point me in the right direction to where I can find a tutorial about this or explain it to me, it would be really helpfull.

    Thanks in advance,
    Dirk


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: SwingWorker class, the process method

    Can you post a small code with the error so that it can be compiled and generate the error message?
    Your two lines of code won't compile.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Feb 2012
    Posts
    58
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: SwingWorker class, the process method

    There are no errors but the process method is never executed.
    The API document explains well enough, that is, the process method is called by the publish() method which should be invoked from the doInBackground() method. Consult the Java API document for more details.

Similar Threads

  1. SwingWorker - max memory?
    By fractalorbit in forum AWT / Java Swing
    Replies: 1
    Last Post: September 15th, 2011, 02:58 PM
  2. Accessing a method of one class in another class
    By Sai in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 23rd, 2010, 04:06 PM
  3. updating EDT with thread swingworker/invokeLater ?
    By mdstrauss in forum AWT / Java Swing
    Replies: 0
    Last Post: October 11th, 2009, 04:52 AM
  4. swingworker OR a swingUtilites.invokeLater()
    By mdstrauss in forum AWT / Java Swing
    Replies: 0
    Last Post: October 11th, 2009, 04:50 AM
  5. Replies: 0
    Last Post: October 10th, 2009, 01:25 PM