• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

another head first beatbox question

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the book the beat-box is limited to only allowing one save as the file name is hard coded into the file out put stream. I have been trying to put in a file chooser so you can save more then one file; so far i can get the file chooser to open and save a file but i cannot retrieve the file information (the checkbox state that i want to save)

need some help here below is the code
 
Marshal
Posts: 80634
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Are you clicking the "approve" or "yes" button on the file chooser? If so, the showSaveDialog method has an int return type. Shouldn't you check that against the constants in the file Chooser class, something like this?Also your next if isn't quite right. You should beware of if (b) b2 = true; and the version with if-else is even worse. You do sometimes really need if (b) b2 = true;, but I suspect not here. What is happening is that you are gradually setting the check boxes to true and never setting them to false. Try something likeYou will notice an if has gone, and so has the cast. Since you have given the List an actual type parameter of JCheckBox, there is no need for any casting. Always use parameterised types, to avoid casting, because casts are nasty, error-prone things. I have also taken the 256 out. Number literals like that (called "magic numbers") are error-prone when used on arrays.
 
Campbell Ritchie
Marshal
Posts: 80634
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I earlier wrote:. . . Try something like. . .

. . . which can be abbreviated to
checkboxState[i] = checkList.get(i).isSelected();
But you must always ensure the array and the list are the same size. Maybe two arrays, declared as final , instead, so they will always be the same size??
 
michael dej
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok and these are going to into the fileSaved of fileOpen?

i know it's probably a silly question. i'll try this but the problem i get is i don't think it's saving correctly, as any changes i make after are still there when i restore (ex ample i uncheck several boxes, and restore because i don't like the change the file appears to open(no errors) but nothing changes)


{edit} i just put the code you suggested in the file save part, and still have the same issue. it must a save issue not writing the checkbox state (at leat that's my current thinking)


here is the original way it way saved


this way worked fine but now i want to incorporate a file chooser option
 
Campbell Ritchie
Marshal
Posts: 80634
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't matter what you do with those values at this stage. Get the values, print out all the values in the array, and then you will have some idea whether it works. Then consider the next stage, of printing the values in a file.

You want to program only a few lines at a time, get them working, then write a few more lines.
 
michael dej
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is part of the file retrieval i set a print when i saved and when i opened a file the save gave me the boolean states,whereas the open gave back nothing at all
 
michael dej
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok i figured it out, finally
 
Campbell Ritchie
Marshal
Posts: 80634
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done

. . . but how did you sort it out?
 
michael dej
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i swapped the for and try parts under save, and i took out the ".ser" under the file stream for both.


the problem i have now is i get no file extension when i save, that i haven't figured out yet




 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic