Sample showing a network component having two nodes and a link

Article ID: 2147
Last updated: 28 May, 2018
Article ID: 2147
Last updated: 28 May, 2018
Revision: 3
Views: 681
Posted: 14 Jan, 2004
by Dean J.
Updated: 28 May, 2018
by Gargani A.


How to create a network component with two nodes and a link?


This basic sample shows a network component in a window. The network contains two elements with a link between them.

import ilog.cpl.IlpNetwork;
import ilog.cpl.graphic.IlpPoint;
import ilog.tgo.datasource.IltDefaultDataSource;
import ilog.tgo.model.IltLink;
import ilog.tgo.model.IltNetworkElement;
import ilog.tgo.model.IltOSIObjectState;
import ilog.tgo.model.IltObject;

import javax.swing.JFrame;

public class Main {
   // This sample uses JViews TGO features.  When deploying an
   // application that includes this code, you need to be in possession
   // of a JViews TGO Deployment license.
   // unComment the following line of code if using JViews TGO 8.8 or earlier.
   // IlvProductUtil.DeploymentLicenseRequired( IlvProductUtil.IBM_ILOG_JViews_TGO_Deployment);
    public static void main(String[] args) {
        IlpNetwork network = new IlpNetwork();
        createFrame("JTGO Basic Network Sample", network);

    static IltDefaultDataSource createDataSource() {
        IltDefaultDataSource dataSource = new IltDefaultDataSource();

        IltNetworkElement element1 = createElement("First", 50, 50);
        IltNetworkElement element2 = createElement("Second", 150, 150);
        IltLink link = createLink("Link", element1, element2);
        return dataSource;

    static IltNetworkElement createElement(String name, float x, float y) {
        IltNetworkElement element =
            new IltNetworkElement(
                new IltOSIObjectState());
        element.setPosition(new IlpPoint((float) x, (float) y));
        return element;

    static IltLink createLink(String name, IltObject from, IltObject to) {
        IltLink link =
            new IltLink(new IltOSIObjectState(), name, IltLink.Media.Fiber);
        return link;

    static JFrame createFrame(String title, IlpNetwork network) {
        JFrame frame = new JFrame(title);
        frame.setLocation(50, 50);
        frame.setSize(400, 400);
        return frame;

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2147
Last updated: 28 May, 2018
Revision: 3
Views: 681
Posted: 14 Jan, 2004 by Dean J.
Updated: 28 May, 2018 by Gargani A.
Also listed in

Others in this category