• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Java MIDI BeatBox Clearing

 
Ranch Hand
Posts: 49
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I wrote this program as a sort of BeatBox - each checkbox corresponds to a beat by a different instrument

I would like to have all the checkboxes clear when the user clicks the "Reset" button

I don't know how I would do this - maybe a repaint() method?

Thanks for the help!

Code:

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way to clear a JCheckBox is to setSelected(false). To clear a number of checkboxes, you would do that for each one, either individually, or, if they have been added to an array or List, in a loop.
 
Franklin Marquette
Ranch Hand
Posts: 49
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay so do a for for each of the 16 rows like this:



And then within that for do another for to loop through the 16 columns like this:



And within the inner for loop would I then just put JCheckbox.setSelected(false);

As that loops through shouldn't it clear all the checkboxes?

Thanks
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Franklin Marquette wrote:And within the inner for loop would I then just put JCheckbox.setSelected(false);

As that loops through shouldn't it clear all the checkboxes?



What happened when you tried it?
 
Marshal
Posts: 64633
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had to break the long lines in your first post because they are so difficult to read, and you can see how you should do it. Look at lines 16-22.

This message will self‑destruct in 24 hours.
 
Franklin Marquette
Ranch Hand
Posts: 49
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does nothing when I press the "Reset" button

Code:

 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does nothing because you're not calling setSelected(...) of the JCheckBoxes in your GUI, but rather of new instances that aren't seen anywhere, and go out of scope immediately thereafter.
 
Franklin Marquette
Ranch Hand
Posts: 49
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay so I added a new reset function and I believe it works - I also added a way to save and load a beatbox pattern

It compiles fine but the "Load Pattern" and "Save" buttons don't show up and there is only one checkbox instead of 256(16 X 16)

I am lost on how to solve this

If I click on the one checkbox that appears it plays all the sounds and when I click reset it clears the one checkbox - so the reset seems to be working

Here's the code:

 
Campbell Ritchie
Marshal
Posts: 64633
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What sort of layout are you using to set the locations of your check boxes? It sounds as though you have got a problem with the layout.

Added later:

Franklin Marquette wrote: . . . there is only one checkbox instead of 256(16 X 16)
. . .
If I click on the one checkbox that appears it plays all the sounds and when I click reset it clears the one checkbox - so the reset seems to be working
. . .

That sounds as though you have all 256 in the same location.
 
Franklin Marquette
Ranch Hand
Posts: 49
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay I got it fixed - works perfect now

Thanks everyone for all the help!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!