We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,382 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Loading Bar Help

When I run this loading bar script the bar doesn't load and then it loads to the maximum. how come this load bar doesn't work thanks for the help.

// The "LoadBar" class.
import java.awt.*;
import hsa.Console;

public class LoadBar
{
    static Console c;           // The output console

    public static void main (String[] args)
    {
	c = new Console ();

	double load;
	int loaded, total, a, loadbar;
	a = 0;
	total = 100;
	loaded = 0;
	Font loading = new Font ("Ariel", Font.BOLD, 30);

	while (a == 0)
	{
	    int i = 0;
	    c.clear ();
	    load = (loaded * 100) / total;
	    loadbar = (int) Math.round (load);
	    c.setColor (Color.green);
	    c.fillRect (10, 75, loadbar, 10);
	    c.setColor (Color.black);
	    c.setFont (loading);
	    c.drawString ("Loading", 250, 50);
	    
	    for (i = 0 ; i <= 1000000000 ; i++)
	    
	    loaded = loaded + 1;
	}


	// Place your program here.  'c' is the output console
    } // main method
} // LoadBar class
2
Contributors
2
Replies
3 Hours
Discussion Span
2 Years Ago
Last Updated
3
Views
Question
Answered
sirlink99
Practically a Master Poster
694 posts since Oct 2010
Reputation Points: 58
Solved Threads: 19
Skill Endorsements: 2

The problem is the for loop. Before it executes, loaded=0 so there's nothing to draw, and after it will be something like 1000000001. Only then will the bar be drawn again.

kramerd
Posting Pro in Training
405 posts since Sep 2010
Reputation Points: 49
Solved Threads: 75
Skill Endorsements: 0

I fixed it by putting loaded = loaded in the for loop and then adding one to it after the loop. I made an if statement that says when the loaded = 50 then it prints done loading and exits the while loop. thanks for the help.

sirlink99
Practically a Master Poster
694 posts since Oct 2010
Reputation Points: 58
Solved Threads: 19
Skill Endorsements: 2
Question Answered as of 2 Years Ago by kramerd

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0596 seconds using 2.69MB