Saturday, November 22, 2014

JList: control over selection

Control over selection in list items is possible through three constants defined in ListSelectionModel.interface.
    This constant is used if we want to restrict the selection to at most one item.
    This constant is used if we want to select the items in regular way, i mean in sequential way. So we can't select item at first position  and an item at 4th position. We have to use shift key to select more then one item.
    This is the default selection mode for JList instance. In this case we can select items also with multiple interval, i.e. by pressing control key, we can do random selection of items, however both of the above is also applicable. View in details here

If want to know about how to use JList in swing application click here.

Friday, November 21, 2014

How to generate random no.

I have shown here the different ways to generate random no.
1. How to generate random no. in specified no. of digit.
2. How to generate random no. from 1 to n
3. How to generate random no. between given range
to see the answer watch here

A simple Game in java

I have made a simple game in java to demonstrate the use of random no.
This will give a flavor of game programming using java.

To know different ways to generate random no. in java Plz. read here.

JList: How to create list in java swing.

To show list of items in java swing, we have a javax.swing.JList component.
Following steps needed to create list
1. Create list of items as String array.
2. Create instance of a JPanel
3. create the object of JList by passing items array as parameter to its constructor.
4. Now add the instance of JList to panel.
5. add the panel to your frame
6. set the size and visibility of your frame.
7. Test your program.
or watch the following video that i have uploaded for easy reference.