• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Circular Progress Bar

 
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hello
I found this code on youtube
I do not understand the error line 80 and 81
Thank you for your help
 
Saloon Keeper
Posts: 12804
278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would really make it easier for us to help you if you actually told us what error you are getting.
 
Master Rancher
Posts: 4250
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I found this code on youtube


Can you post a link to where you got the code?
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK sorry
Bar Cannot Be Resolved Or Is Not a Field
I did not really understand what he did

webpage
 
Norm Radder
Master Rancher
Posts: 4250
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you download the source code from?  Can you copy the link and paste it here?
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not download
I have a copy by hand looking at the video but I did in single piece

Click on webpage I gave you the link

https://www.youtube.com/watch?v=j8y0mRdBKHo
 
Norm Radder
Master Rancher
Posts: 4250
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I was trying to get some background on where the code came from.  If you typed it all in yourself, then you need to go back to the website and see where you missed something or made a mistake.
Compare your code to the website's code and fix yours to match.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to look again another time and keep you informed
 
Stephan van Hulst
Saloon Keeper
Posts: 12804
278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error message tells you exactly what's wrong: "bar cannot be resolved or is not a field".

What does bar refer to, according to you? If you look at the documentation for Thread, you will see it contains no bar field.

Presumably you want to call the update(int) and repaint() methods of an instance your CircularProgressBar class. However, you have not created an instance of that class, and you don't use it in the frame that you create inside your main method.

It appears you have some gaps in your understanding of object oriented programming. Googling for source code might not be the best way to go about developing apps.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bah uh, I do not know what to answer
I'm standing as I can
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found a circular progress bar code in github
I will be able to work on it and understand my mistake
They are very similar
 
Rancher
Posts: 3232
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know how to create a JLabel, invoke the setText() method and add the label to the frame?

Well your CircularProgressBar is no different. It is a component just like the label.

So you need to create an instance and add the instance to the frame.

Once you have an instance of the component you can then invoke a method on the component. In this case you want to invoke the update(..) method.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JLabel label = new JLabel();

public void setText()
{
      frame.add(label);
}
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I looked at the circular progress bars
everything is done in 3 classes and not in one block
I thought I did a single block but I wonder if it's possible
 
Rob Camick
Rancher
Posts: 3232
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is that code you posted? What text to you expect to see on the label added to the frame?

How do you expect to create a custom component when you can't use use a component from the JDK?

Start by reading the Swing tutorial for some basics.


 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




I have some little improve the code
but I do not understand why the button disappears and appears when I click on
 
Saloon Keeper
Posts: 7999
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each time you click BUTTON it creates a new Thread even if the previous one isn't finished. All threads refer to the same progress object so multiple threads will have chaotic behavior. You are updating the customPanel off of the EDT which you shouldn't be doing.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You are updating the customPanel off of the EDT  



I do not see how to do
 
Norm Radder
Master Rancher
Posts: 4250
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think there is a problem with the layout manager and the components being added to the JFrame.  The Borderlayout has regions for positioning the components.  The add statements (lines 23 & 27) are not saying which region the component is to go in.
 
Saloon Keeper
Posts: 4346
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should make your customPanel (bad name) selfcontaining. So, you should set its size via overriding the 'getPreferredSize' method, or using setPreferredSize. You could specify this size in a constructor. And in your update method, call repaint(). Of course, the size and positon of the circle, the arc  and the font should be relative to that size as well.
So:

and


Norm is right. Invoking 'frame.add(a)' will result in adding a to the contentpane's BorderLayout.CENTER.
Invoking this more than once will usually result in only seeing a last one added. Why you do see the button here (it is not the last one added) is a bit strange, but probably has to do with setting its bounds manually. If you leave that out, then the button will not be visible.
A simple remedy would be to start the constructor of the frame as follows:
.
 
Norm Radder
Master Rancher
Posts: 4250
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another issue that should be fixed is the use of too many hard coded int values.  For example the value 100 is used where the variable radius should be used.  
The values used in the call to the translate method should be computed instead of hard coded.
 
Piet Souris
Saloon Keeper
Posts: 4346
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And, while we're busy, there is Careys remark about pressing the button successively, resulting in chaotic behaviour. Can you think of a way to ignore button presses somehow while the progressbar is running?
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will think about everything
I do not know how I'm going to take it
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just add a borderlayout.south
Thank you
 
Carey Brown
Saloon Keeper
Posts: 7999
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding the issue of updating the CPB (Circular Progress Bar) off of the EDT, a SwingWorker is the easiest way to handle that. I was playing around with your code and this is what I used. This also handles the multiple button click issue.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thank you for the code
I have a little trouble running it but otherwise it's going
if I understand correctly with the edt
The EDT does not use Thread.sleep while Swingworker l uses
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it must be the opposite
I mix a little
I am reading on edt and swingworker
 
Carey Brown
Saloon Keeper
Posts: 7999
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ronald deux wrote:I thank you for the code
I have a little trouble running it but otherwise it's going
if I understand correctly with the edt
The EDT does not use Thread.sleep while Swingworker l uses

Correct. You do not want to put the EDT to sleep because then it can't respond to user events. With SwingWorker you can sleep in doInBackground() because it is NOT on the EDT, but you do NOT want to sleep in process() because that IS on the EDT.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I like to work with the audio then I put music, the circular progress bar ends and respects the time of the song but I will try with swingworker and not swingworker
 
Carey Brown
Saloon Keeper
Posts: 7999
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just remember to play the music in its own thread but NOT update the progress circle from that thread, you must update it on the EDT. This can be done without SwingWorker but it's trickier.
 
Carey Brown
Saloon Keeper
Posts: 7999
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without the SwingWorker you need to use Swing's invokeLater() method which you call off of the EDT and then it makes the requested call on the EDT but it is only sort of synchronus. For your purposes this wouldn't even be noticable.

An example with a normal JProgressBar:

 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will document a little more about the edt, swingworker and invokelater to understand
and find examples
 
Piet Souris
Saloon Keeper
Posts: 4346
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take your time, it is not an easy subject at all.

One remark: there is no need for a SwingWorker to update any ProgressBar. A SwingWorker has a bean property called "progress" and if that property is changed, it notifies all PropertyChangeListeners that have been added to that SwingWorker about the change. In the API of a SwingWorker you can find an example (but again: not so easy). If you ever come to this point, give us a sign.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK no worries
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




Hello

 I try to move this circular progress bar using the Corey code on Hashmap Sound
she does not move but we hear the music well
Thank you for your help
 
Carey Brown
Saloon Keeper
Posts: 7999
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't think it was going to be so difficult to get this to work. The hair pulling was over being able to play the track or being able to animate the progress bar but not both. Solution: see placement of start() and close(). It came down to a trial and error hunt. I hate those.

Also, this releases the EDT which causes it to try to play the next track immediately so you end up with multiple tracks playing at once and arm wrestling over who gets to update the progress bar. You'll need something to tell the for() loop around the call to play() to wait till the current track is done. SwingWorker has a done() method that can be utilized for this but for now I'm taking a break.

I also suspect the progress bar is being updated off of the EDT so may need to be wrapped in an invokeLater().

 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I managed to make a simple progress bar
For the circular progress bar, I come to try New Thread
(New Runnable () {}, I hear the music play at the same time
 
Die Fledermaus does not fear such a tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic