🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #18554

Re: Progress Indication from a thread

#18554
From: Jim Rudnicki
Date: Wed, 10 Jun 1998 00:00
90 lines
2768 bytes

>I am writing a server application.  The application (Class FrameServer) has
>a textarea to display a log of all activities the server is performing.
>When a connection is made I spin off a thread (Class
>ThreadedRequestHandler).  I would like to be able to write a line to that
>textarea to show actions performed by ThreadedRequestHandler.  For
>example...


>I am clueless as to how I can accomplish this.  I tried to add a public
>method to FrameServer  and then I tried to call the method from
>ThreadedRequestHandler.  I got an errormessage to the effect that non
static
>method cannot be referenced from a static context.  Any suggestions?


I've been using something like this lately:

interface RequestHandler_listener{
    void public takeProgressMessage( String s );
}

class RequestHandler{
   private RequestHandler_listener m_Listener;
/* ya could even make this a list and add any number
of listeners */
    void addListener( RequestHandler_listener l ){
        m_Listener = l;
    }

  /*  then somewhere ... */
    if( null != m_Listener )
        m_LIstener.takeProgressMessage( new String( "show this") );
}

/* the parent/owner */

class Owner
    implements RequestHandler_listener
{

/* somewhere */
    rh = new RequestHandler();
    rh.addListener( this );


    public void takeProgressMessage( String s ){
        // show it
    }
}

/* Plan b )
More simple but less reusable
Pass a pointer of the owner to the handler */

class RequestHandler{
   private Owner m_Parent;
/* yada */
    void setParent( Owner p ){
        m_Parent = p;
    }

  /*  then somewhere you can call any publics in the parent */

    if( null != m_Parent )
        m_Parent.updateTextBox( new String( "show this") );
}


class Owner
{

/* somewhere */
    rh = new RequestHandler();
    rh.addParent( this );

    public void updateTextBox( String s ){
        // show it
    }
}


In the above a call such as Owner.updateTextBox() would require that the
method be static.  You have not given a reference to the object.  But making
the method static is no way out.  A static method can only access static
members, so your text box would not be accesible.

luck
Jim
Technical Details
Message-ID: <6lletb$8o84@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6lkb4i$9m5$1@chile.it.earthlink.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,237ac3e7eba56d73
X-Google-Attributes: gidf74b3,public
From: "Jim Rudnicki" <rudnicki@best.com>
Subject: Re: Progress Indication from a thread
Date: 1998/06/10
Message-ID: <6lletb$8o84@forums.borland.com>
X-Deja-AN: 361294472
References: <6lkb4i$9m5$1@chile.it.earthlink.net>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language