Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7030831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:43:24+00:00 2026-05-28T00:43:24+00:00

I modified the sample code for Activator posted on the Oracle/Sun AWT tutorial page

  • 0

I modified the sample code for Activator posted on the Oracle/Sun AWT tutorial page here

The modification is as follows

f.add(new MyCanvas(f.getGraphicsConfiguration()), 
             BorderLayout.CENTER); 

The paint method in MyCanvas is overridden as follows

MyCustomRunnable mcr = new MyCustomRunnable();
Thread th = new Thread(mcr);

th.start();

while(Thread.currentThread().isAlive()){
    mcr.getData();
    //do UI stuff 
    Thread.yield();
}

Similarly MyCustomRunnable has a corresponding loop in run()

public void run(){
    while(Thread.currentThread().isAlive){
        //do Stuff
        Thread.yield();
    }
}

The Runnable, and Canvas paint (both) run a loop. With this bit of code running, System Menu close on the UI window are not invoked. Why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:43:25+00:00Added an answer on May 28, 2026 at 12:43 am

    The short answer is that paint() is called on the event thread, which is also the thread that handles all UI events, and you are taking over that thread and putting it into an infinite loop.

    When you are doing this in the paint method…

    while(Thread.currentThread().isAlive()){
       ...
    }
    

    … the “current thread” you are working on is the same thread you entered that method on, which is the “event dispatch thread”. I would guess that what you really wanted was to run a background thread that periodically repaints the view. You could do this in the constructor of your AWT component:

    new Thread() {
       public void run() {
          while(runBackgroundThread) {
             mcr.getData();
             repaint();
          }
       }
    }.start();
    

    Note that I also created a boolean variable runBackgroundThread which would be a volatile field in the component class. Setting it false would stop the loading thread. In contrast, Thread.currentThread().isAlive() will always be true – the currently running thread must by definition be alive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using slightly modified sample code provided by the YUI team. When my source
I am using a modified version php-sdk version 3.0.0 sample code at github.com/facebook within
Here's the code. Not much to it. <?php include("Spreadsheet/Excel/Writer.php"); $xls = new Spreadsheet_Excel_Writer(); $sheet
I have modified the Apple sample code TableSearch, but there is one thing I
I find this sample code and i modified the code to make it do
I am new to WP7 coding. I am looking for sample code or guiding
I'm using the following code (which is a sample from the MSDN slightly modified)
I'm using some barely modified sample code from Facebook to post to a user's
I got a Making Layers that Move javascript sample code and modified the functions
Here is an abstract JavaScript code sample that illustrates the situation that is causing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.