Java visual stuff

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Java visual stuff

Post by shiznatix »

Ok so I am working with a progress bar and I have got it to work no problem. Super! The problem though is that after I start the program that uses the progress bar, the rest of the elements freeze. Like the menu bar, if I minimize the applet as it runs the file upload then restore it the menu bar will be transparent kinda as it will not be the menu bar anymore but what was behind it (like when a program freezes and you try to maximize it again or something). Everything goes back to normal when the program finishes the main loop.

I was wondering how I could make this menu stay visible at all times without it going into freeze mode. Here is the relative code:

Code: Select all

//THE UPLOADING LOOP
while ((current_byte = bufferedinputstream.read()) != -1)
            {
            	iteration = iteration + 1;
            	
            	float percent = percent_per_iteration * iteration;
            	
            	shiznatix.VisualElements.SetProgressBarValue((int)percent);
            	shiznatix.VisualElements.SetContent("");
            	
                bufferedoutputstream.write(current_byte);
            }
//END THE UPLOADING LOOP

//THE VISUAL ELEMENTS METHODS
public void SetProgressBarValue(int Percentage)
    {
    	progress_bar.setValue(Percentage);
    	
    	Rectangle progressRect = progress_bar.getBounds();
		progressRect.x = 0;
		progressRect.y = 0;
		progress_bar.paintImmediately(progressRect);
    }

public void SetContent(String str)
    {
    	if (str != "")
    	{
    		content.append(str + "\n");
    	}
        
        Rectangle progressRect = content.getBounds();
		progressRect.x = 0;
		progressRect.y = 0;
		content.paintImmediately(progressRect);
    }
I use the SetContent in the loop to make the content text block not do the same thing the menu bar is doing.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Run your upload loop in a different thread because right now it is in your ui-dispatch-thread.. And as you can see it keeps your application from repainting itself etc...
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Yay for multi-threading.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You are aware that a JProgressBar class exists right? ;)

http://java.sun.com/j2se/1.5.0/docs/api ... ssBar.html
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

d11wtq wrote:You are aware that a JProgressBar class exists right? ;)

http://java.sun.com/j2se/1.5.0/docs/api ... ssBar.html
:) yes, that is what progress_bar is, a JProgressBar. But I am using the paintImmidiatly() stuff because the event listener everything is too much for me right now. Maybe tomorrow.

Multi-threading and all of that, could you give me an example of how I could run this in another thread. I don't really understand and the online stuff is going over my head.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Simply follow the link d11wtq provided you... http://java.sun.com/docs/books/tutorial ... gress.html and notice the writings about SwingWorker...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I never used to like the Java documentation but now I do and I think the only reason I didn't like it before was because it felt a bit unfamiliar after being so deep in PHP for so long. I do wish they'd make it easier to search from any one page to the next though; unless I'm missing something you have to go back to the search page to start a new search. User comments would be good too for obvious reaons :)
Post Reply