MrUber MrUber - 5 months ago 18
Java Question

Creating "Tips on StartUp" in Java Swing

So I have created a program in Swing, fully functional etc etc. Now I'm taking care of the usability and thought it would be nice to create a tips on startup "presentation" so the users can more easily get accustomed to the program.

I think that the best way to go about this is to create an ArrayList, add all the images, and then, when the user presses the "Next" button, get the i++ element of the list, and set the element value

This is my window (white represents image):

enter image description here

This is pretty much how the code is:

LinkedList<Image> alist = new LinkedList();
alist.add("image1.jpg");
alist.add("image2.jpg");
alist.add("image3.jpg");

onNext() {
element.setValue(aList.get(i++));
}


Note that the class and the images are in the same package

So my questions are


  1. I'm having trouble adding the images to the list, and I'm not sure how to properly do it.

  2. What element can I use to be able to set its value to image?

  3. In order to have the option show tips on Startup (and remember it between executions), what do I have to do? I've thought about serializing a boolean, and when the program starts, deserialize, if(boolean) showTips. Is there some easier way I'm missing?


Answer
  1. There is no need to store the Image in the list. If you do then you will need to read all the images in at start up which may take time. Instead you can do what you are doing which is just store the image file name. The image can be loaded when the tip is displayed.

  2. You can use a JLabel to display an ImageIcon. Read the Swing tutorial on How to Use Icons for more information and working examples. To change each image you can just use the setIcon(...) method of the label.

  3. You can use a Properties file. Read the API it has methods to read/write and query the properties.

Comments