Concurrent Programming with Java
Lab Manual, Version 1.0, F. Astha Ekadiyanto,
2002.
Lab 2: Building Application
Constructing Topology using Bluej in the previous section will certainly consume a lot of time. More over, once you have successfully constructing the topology, you will definitely don't want to go through the same work again each time you have to reconstruct them. But learning to construct the topology manually may help you to know the steps and hopefully be able to write a Java code for it.
This page will guide you to define the topology in a new Class definition called MobileSystem Class. This Class is a subClass of Msc with a defined topology in it. A MobileSystem should have a String name field that represents a Firm/Company/Brand name (i.e. "VodaPhone"). The only additional behavior necessary is regarding to the name of the MobileSystem itself (probably getName()). The topology definition of the MobileSystem will be defined when the MobileSystem Object is initialized. Thus, this should be performed in the Class Constructor method.
To construct the topology, we will define all the steps in constructing
topology using BlueJ into Java code.
The steps are as follows:
Cell tempCell = new SquareCell(95,230,20); |
Rbs tempRbs = new Rbs("RBS-1",new SquareCell(95,230,20)); |
addRbs(tempRbs); |
addRbs(new Rbs("RBS-1",new SquareCell(95,230,20))); |
Rbs tempRbs1 = findRbs("RBS-1"); |
Msc.setNeighboring(findRbs("RBS-1"),findRbs("RBS-2")); |
public void setNeighboring(String station1, String station2) { Rbs rbs1 = findRbs(station2); Rbs rbs2 = findRbs(station1); if ((rbs1 != null) && (rbs2 != null)) Msc.setNeighboring(rbs1, rbs2); } |
The complete codes of this stage is in the followings.
File name : MobileSystem.java
public class MobileSystem extends Msc { private String name; /** * Constructor for objects of class MobileSystem */ public MobileSystem(String name) { //Creating Mobile Network Topology this.name = name; addRbs(new Rbs("RBS-1", new SquareCell(95,230,20))); addRbs(new Rbs("RBS-2", new HexCell(125,210,20))); addRbs(new Rbs("RBS-3", new HexCell(90,190,20))); addRbs(new Rbs("RBS-4", new HexCell(160,190,20))); addRbs(new Rbs("RBS-5", new CircleCell(125,170,20))); addRbs(new Rbs("RBS-6", new HexCell(160,150,20))); addRbs(new Rbs("RBS-7", new SquareCell(125,130,20))); addRbs(new Rbs("RBS-8", new CircleCell(90,150,20))); addRbs(new Rbs("RBS-9", new CircleCell(55,170,20))); //Registering neighboring Cells setNeighboring("RBS-1","RBS-2"); setNeighboring("RBS-2","RBS-3"); setNeighboring("RBS-1","RBS-3"); setNeighboring("RBS-3","RBS-5"); setNeighboring("RBS-3","RBS-9"); setNeighboring("RBS-3","RBS-8"); setNeighboring("RBS-2","RBS-5"); setNeighboring("RBS-2","RBS-4"); setNeighboring("RBS-5","RBS-4"); setNeighboring("RBS-4","RBS-6"); setNeighboring("RBS-5","RBS-6"); setNeighboring("RBS-5","RBS-7"); setNeighboring("RBS-5","RBS-8"); setNeighboring("RBS-6","RBS-7"); setNeighboring("RBS-7","RBS-8"); setNeighboring("RBS-8","RBS-9"); } public String getName() { return name; } /** * Overflow SuperClass method to enable different argument (Polymorph) */ public void setNeighboring(String station1, String station2) { Rbs rbs1 = findRbs(station2); Rbs rbs2 = findRbs(station1); if ((rbs1 != null) && (rbs2 != null)) Msc.setNeighboring(rbs1, rbs2); } } |