Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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 Pie Elite 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

JProgressBar Sound

 
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 wrote this code on three progress bars, it seems to me repetitive, can you give me your expert opinion ???
Thank you for your help
 
Marshal
Posts: 72477
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you do have some repetition. Can you set up the progesss bars in a loop?

Moving to our GUIs forum.
 
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 mean like the last time?
 
Campbell Ritchie
Marshal
Posts: 72477
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which last time?
 
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
Jprogressbar array topic
if I understood correctly, I do not use array but just loop
 
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
should you use for loop for actionPerformed?
 
Saloon Keeper
Posts: 4358
163
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well,

you can certainly get rid of all those duplications. For iNstance, make a method 'private void getJProgressBar(required parameters), so that you can invoke that method for every JPB that you want to create. And more or less the same for your method 'actionPerformed': there are many variables that you can derive from the source of the event. For instance, you can set up a Map<JButton, File>, and derive the file as map.get(ae.getSource()).

And, I have written before, do NOT use Thread.sleep() on the EDT (thats the thread where your actionListener is executed). You might not notice any delay, but tRY dragging your window around, or watch any other animation that you may have running and see what happens.

I gave you an example of how to deal with JPBs. You never commented on that, but I suggest you give it a(nother?) read.
 
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'll see what I can do
Thank you for your advice
yes I remember the last time, I will have to read it again
 
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 am looking for a way to number the buttons in how by 00 or 01 going down that is to say
01
02
03
and no
03
02
01
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should these numbers be the text on the buttons? Then, if you have this method 'private JProgressBar createJPB(arguments)'  (in my earlier reply I talked wrongly about 'private void,' sorry about that), then you can make the text an argument. For instance:
 
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 everywhere on the internet private void get ...
I spent the day there understanding
I wondered for a moment if we shouldn't install a get and a set
I agree, there is a mistake
but hey it does not matter, I told myself that I will find something else
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To avoid any misunderstanding, this is a prototype of what I meant:
 
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
not serious about the mistake, everyone makes mistakes
and by the way thank you for the prototype
it helps me understand
 
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 modified your prototype in my own way
I can't display the buttons and progress bars
what more is needed?
 
Campbell Ritchie
Marshal
Posts: 72477
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't make display classes implement action listener. That leads to unmanageable long methods.
Don't extend JFrame. A display HAS‑A JFrame; it ISN'T‑A JFrame. Even worse if you have a frame with a frame as its field. Where did you initialise either frame, and where did you set them visible?
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two reasons why you see nothing of what you expected:

1) You have a class 'KFrame' that contains all you want, but in 'main' of class 'JProgressBar05' you create a normal JFame and show that.

2) in class 'KFrame' you forgot to add the panel to the frame. You have a field 'frame' in this class, but since KFrame is already a JFrame, you can skip this field and just do: this.add(panel).

I have the corrected code below, with some comments and a temporary method 'processButtonclick', so that you see it works.

As you will see, the layout is not yet perfect, the bounds need some fixing. And that is the problem with setting all bounds yourself: it is pretty hard to get things correct, and if you later want to replace one or more components, you face the risk of having to change quite some bounds! There are much better ways to create nice layouts, but leave things for now as they are.

As an experiment, leave out the line: panel.setLayout(null), and notice the difference.

Here is the updated 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
thank you for the prototype, I hadn't seen my mistake
I put JFrame frame instead of KFrame frame = new KFrame ();
I understood with actionlistener
and then I don't like JPanel unless I do setLayout (null)
 
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 trying to perfect the piet mouse prototype
by HashMap <JButton, File>
not sure that we can put JButton, File as HashMap
I did JButton, String
there is not much info on JButton HashMap
Thank you for your help
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at the method 'actionPerformed' in the code in your opening post. If I read that code well. it boils down to knowing two things: what file is involved with the clicked button, and what JProgressBar is involved?

Now, we only know the JButton that is clicked or pressed, via actionevent.getSource().
So the question is how to get the correct File and the correct JProgressBar? Having two Maps is an easy solution. Have a field Map<JButton, File> and a field Ma<JButton, JProgessBar>. The latter one can be filled in the constructor (it is a constant), where you create the JButtons and the JProgressBars, the former can be filled whenever you load the music Files.

So, in the method 'processButtonclick' that I proposed, you must do what you did in your actionPerformed method:
- determine the button involved, by: JButton clicked = actionevent.getSource()
- get the File with: File f = buttonToFileMap.get(clicked)
- determine your data and the Clip.
- set up a Timer that calls every second the involved JProgressBar (derived from the other map) and update that progressbar.

Well, something like that. Have you already an idea how your GUI will look and how exactly your code will function?
 
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 know how I want to do it, I know the graphic appearance, try with two or three music files
a file for each progress bar much like a jTable
my code, I know how it works
if I can do better with your ideas, why not try it with hashmap, timer ... so I can learn a little more
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if my ideas are better than yours, I haven't seen any working code. So, if you have working code, please show us that code. My idea is that of a clone of WinAmp, so wouldn't be of any use to you.
 
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 you don't know if your hashmap ideas would work with what i want to do with two or three music files
history of learning
when the functional code, I don't have, I only have this one
I just saw WinAmp, wow,
I'm not here yet
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, my HashMaps are not a must. The topic was about avoiding all tose repeats in the code of your opening post. There you had three if/else ifs, and you did much unneccessary work. Therefore I mentioned those HashMaps. But if you can think of handier structures then use these.

But what I wanted to know: do you have a working version that plays music and has a JProgressBar going?
 
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 code on FOBEC with play pause keys ... but the progress bar does not work
so I adapted my progress bar to my way
otherwise I went to stackoverflow
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. Success with SO then.
 
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
yes
 
Campbell Ritchie
Marshal
Posts: 72477
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you were successful finding the answer on SO, please show us a link so we can see what the answer is for ourselves
 
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
what is SO?
you mean FOBEC
I don't understand where you are coming from

webpage
 
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
ah ok SO = stackoverflow
 
Campbell Ritchie
Marshal
Posts: 72477
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the link. Yes, I thought you had gone to stackoverflow.
 
Good heavens! What have you done! Here, try to fix it with this 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