The Essential JViews Framework > Getting Started with JViews Framework > Step 4 - Manipulating Graphic Objects > Adding Graphic Objects

To be able to manipulate graphic objects, we must first import the ILOG JViews package that contains the graphic objects:

import ilog.views.graphic.*;

In this example, we implement the addObjects method which adds ten objects of the IlvIcon class to the manager:

public void addObjects() 
{ 
  manager.setSelectable(0, false);

    for (int i = 0 ; i < 10 ; i++) {
        IlvGraphic obj = new IlvIcon("image.gif", new IlvRect(0,0,37,38));
       manager.addObject(obj, 1, false);
    }
}

The first line in this method calls the setSelectable method on the manager with 0 and false as its parameters:

manager.setSelectable(0, false);

The first parameter, 0, specifies the layer in the manager to which the method applies. The second parameter, false, specifies whether objects in the layer passed as the first parameter can be selected (true) or not (false).

Objects in a manager can be stored in different layers, which are identified by indices. Layers are drawn on top of each other, starting at index 0. In other words, the first layer is assigned the index 0, the second layer, the index 1, and so on, with the objects stored in a higher screen layer being displayed in front of objects in lower layers.

In the usa.ivl file loaded in the manager, the objects that make up the map are stored in layer 0. Calling the setSelectable method with 0 and false as parameters specifies that the map (layer 0) cannot be selected, and hence, cannot be modified.

The following addObject method adds the IlvIcon objects to layer 1 of the manager:

manager.addObject(obj, 1, false);

Call the addObjects() method from the application initiation method. In this case the Sample4 method.

Note
 The false parameter of this method specifies that the redraw is not to be triggered. Here no redraw is needed because the application is not visible when this code is executed.

Test the interface of the application by clicking on the objects with the mouse. You can see that the new objects are selectable, whereas you can no longer select or modify the map.