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 7537027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:44:09+00:00 2026-05-30T06:44:09+00:00

I am trying to understand J2ME code Thread aaa = new Thread(pb) { private

  • 0

I am trying to understand J2ME code

Thread aaa = new Thread(pb) { private final ProgressBar val$pb;

      public void run() { while (this.val$pb.getValue() < 100) {
          try {
            this.val$pb.setValue(this.val$pb.getValue() + 1);
            Thread.sleep(10L); } catch (InterruptedException ex) {
          }
          this.val$pb.repaint();
        }
        mainForm.homeScreen = new HomeScreen();
        mainForm.homeScreen.show();
      }
    };
    aaa.start();

please tell me what does pb do in Thread constructor. How this code will look like if I Change new Thread(pb) to new Thread() ? Does it affect val$pb ? above code could not be compiled so I edited like this

Thread aaa = new Thread() { private final ProgressBar val=null ;//new Thread(pb) ProgressBar val$pb;

      public void run() { try {while (this.val.getValue() < 100) { //try added by me
          try {
            this.val.setValue(this.val.getValue() + 1);
            Thread.sleep(10L); } catch (InterruptedException ex) {
          }
          this.val.repaint(); //draws progress bar as a loading screen before showing home screen 
        }
      }catch(Exception e){
        mainForm.homeScreen = new HomeScreen();
        mainForm.homeScreen.show(); // draws home screen
      }
      }
    };
    aaa.start();

EDIT:- it uses J4ME library.

  • 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-30T06:44:11+00:00Added an answer on May 30, 2026 at 6:44 am

    If your code compiles then pb is a parameter to Thread constructor.

    Given that it is a single parameter, it may be either Runnable or String since Java ME API specifies only these objects possible as a single parameter in Thread constructor.

    How this code will look like if I Change new Thread(pb) to new Thread()?

    If pb is Runnable then things likely won’t change because Thread instance aaa overrides run method (which would be otherwise invoked for pb) and because in your code snippet, there are no traces of invoking pb.run anyway else (which smells of design error or of too much code cut from your snippet).

    If pb is String then name of the Thread aaa will be default instead of pb value.

    Does it affect val$pb?

    Hard to tell unless you post more code – preferably in SSCCE form.

    val$pb looks funny but this could be a legal identifier for a variable assuming that in the code snippet you have cut something that initializes it.


    update in the second version of your code, given that you initialized private final ProgressBar val=null – as a result, in the run method statements that invoke methods on it will throw NPE this.val.getValue() and proceed right into catch block that draws home screen according to code comments.


    update2

    if I don’t initialize private final ProgressBar val then it gives error asvariable val might not have been initialized so what would be another way to initialize it?

    Well with limited amount of code in your snippet one can only guess.

    One way that comes to mind is to init with pb, like this:

    //...
    new Thread(pb) { private final ProgressBar val$pb = pb; // ...
    

    above may compile if pb refers to ProgressBar instance and is declared final.

    Note that in this case, val$pb is not quite necessary because pb can be used instead of it (maybe this variable was introduced for code style preferences).

    Also, given your reference to j4me have to admit that using ProgressBar in thread constructor – if pb is an instance of this class – makes very little sense to me. One can only wonder how did it appear there in the initial snippet you posted Thread aaa = new Thread(pb)...

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

Sidebar

Related Questions

just trying to understand this code. $db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
Trying to understand Ruby a bit better, I ran into this code surfing the
After trying to understand why client code is not rendered in a page (injected
I'm trying to understand someone else's Perl code without knowing much Perl myself. I
Trying to understand, why my C++/Qt application creates 18 threads, while i don't create
Trying to understand this binding process of the WPF. See the code at the
Trying to understand, how to redirect program output to a file... Code : import
I trying to understand this piece of code Function.prototype.method = function (name, fn) {
HI Trying to understand how __radd__ works. I have the code >>> class X(object):
Trying to understand how the code below always brings up a number between 0-6

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.