aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes another head first beatbox question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "another head first beatbox question" Watch "another head first beatbox question" New topic
Author

another head first beatbox question

michael dej
Greenhorn

Joined: Aug 31, 2011
Posts: 5
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
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
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
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
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

Joined: Aug 31, 2011
Posts: 5
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
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
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

Joined: Aug 31, 2011
Posts: 5
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

Joined: Aug 31, 2011
Posts: 5
ok i figured it out, finally
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Well done

. . . but how did you sort it out?
michael dej
Greenhorn

Joined: Aug 31, 2011
Posts: 5
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




 
It is sorta covered in the JavaRanch Style Guide.
 
subject: another head first beatbox question