🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Animation revisited (i.e. when does a screen refresh)

#16983
From: Greg Hamer
Date: Thu, 07 Jan 1999 00:00
82 lines
3247 bytes
I think it is because you are hogging the awt thread. The action event comes
in on the tread that will also do the painting. I may be confused, but by
having your class implement Runnable and spawning a thread,  it starts
behaving the way you want:

 public void run() {
   tc1.setText("AFTER");
   for (int j=1; j < 5000000; j++)
    {}
    tc1.setText("MORE");
  }
  void cbOK_actionPerformed(ActionEvent e) {
    new Thread(this).start();

  }

Tom Heagy wrote:

> The following is a simple class that exemplifies my problem with
> refreshing an updated control during a time consuming or delayed
> process.  This frame has a text control with the word "BEFORE" initially
> set.  When the command button is clicked, the text for the control is
> immediately set to "AFTER".  The code then proceeds to loop for a while
> in order to reflect about a 1-2 second delay.  After the delay, the text
> is changed to the word "MORE".  The problem is: You will never see the
> word "AFTER".  The screen won't refresh until after the looping is
> finished.  If anyone can get this to work, I would greatly appreciate
> it.  I'm starting to pull out what little hair I have left in my thick
> skull!
>
> Thanks,
>
> -Tom
>
> ====== LISTING FOLLOWS =======
> import java.awt.*;
> import java.awt.event.*;
> import borland.jbcl.control.*;
> import borland.jbcl.layout.*;
>
> public class TestFrame extends DecoratedFrame {
>
>   BorderLayout borderLayout1 = new BorderLayout();
>   XYLayout xYLayout2 = new XYLayout();
>   BevelPanel bevelPanel1 = new BevelPanel();
>   TextControl tc1 = new TextControl();
>   ButtonControl cbOK = new ButtonControl();
>
>   public TestFrame() {
>     try  {
>       jbInit();
>     }
>     catch (Exception e) {
>       e.printStackTrace();
>     }
>   }
>
>   private void jbInit() throws Exception  {
>     this.setLayout(borderLayout1);
>     this.setSize(new Dimension(443, 365));
>     this.setTitle("TESTING");
>     tc1.setFont(new Font("Dialog", 1, 20));
>     tc1.setText("BEFORE");
>     cbOK.setLabel("Change");
>     cbOK.addActionListener(new java.awt.event.ActionListener() {
>       public void actionPerformed(ActionEvent e) {
>         cbOK_actionPerformed(e);
>       }
>     });
>     bevelPanel1.setLayout(xYLayout2);
>     this.add(bevelPanel1, BorderLayout.CENTER);
>     bevelPanel1.add(tc1, new XYConstraints(82, 69, 93, 35));
>     bevelPanel1.add(cbOK, new XYConstraints(264, 50, 85, 51));
>   }
>
>   void cbOK_actionPerformed(ActionEvent e) {
>     tc1.setText("AFTER");
>     for (int j=1; j < 5000000; j++)
>     {}
>     tc1.setText("MORE");
>   }
> }
Technical Details
Message-ID: <36956C16.7C9EC15C@inprise.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3692836D.C7FE0802@sciatl.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,7fea73d52964a1ef
X-Google-Attributes: gidf74b3,public
From: Greg Hamer <ghamer@inprise.com>
Subject: Re: Animation revisited (i.e. when does a screen refresh)
Date: 1999/01/07
Message-ID: <36956C16.7C9EC15C@inprise.com>
X-Deja-AN: 430036139
Content-Transfer-Encoding: 7bit
References: <3692836D.C7FE0802@sciatl.com>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language