开发者

Saving user settings and images in Java

开发者 https://www.devze.com 2023-02-10 08:22 出处:网络
I\'m writing a program that allows the user to browse their computer for images. When they select an image, then its location (for example \"c:/users/peter/desktop/image1.jpg\") is saved in an array o

I'm writing a program that allows the user to browse their computer for images. When they select an image, then its location (for example "c:/users/peter/desktop/image1.jpg") is saved in an array of strings. Then the user can flip through a "slideshow" of the images they selected. This is done by accessing the arraylist of image locations an setting them as icons for labels.

But what I need help with is saving these images an开发者_StackOverflowd or locations so that everytime the user launches the program it already has the images previously selected by the user. I don't know if this means storing the arraylist of locations or somehow importing/saving the images to program files. Any help or suggestions would be great and please let me know if you need more info.


So, you're basically asking how to remember an user preference? Which is in this case just the user-definied order of images. Well, you could serialize the order to some string in a specific format and then save it in some settings file with help of usual java.io.File stuff, or in a properties file with help of java.util.Properties or even in OS registry with help of java.util.prefs.Preferences. When you start your app again, you just read it again and then deserialize it into an useable Java object which you continue using in your code.

This is by the way in no way related to "working with images".


Saving the arraylist of file locations would be the best option. This would be accomplished by serializing the object to a file and then restoring it on the next run. You can read about object serialization here:

Sun

Tutorial


If you are asking about thumbnail generation

"arraylist of image locations an setting them as icons"

... (either when the user leaves the app, or when he returns to the app), this has been covered numerous times in SO and here is one of the answers.

0

精彩评论

暂无评论...
验证码 换一张
取 消