Concurrent Programming with Java
Lab Manual, Version 1.0, F. Astha Ekadiyanto, 2002.

[Contents] [Next] [Previous]

Lab 3: Building Applets - Graphical representation


Adding draw(Graphics) method in Msc Class

We want to represent an Msc graphically by drawing all the registered Rbs (which is stored in the rbss[] array) into the Graphics context. Since we have defined the draw(Graphics) method of Rbs, we can just call them for each element stored in the rbss[] array.

for (int i=0; i<numOfRbs; i++) 
{ rbss[i].draw(g); }

The complete implementation in Java is shown below.

import java.util.*;
import java.awt.Graphics;
import java.awt.Color; public class Msc {
     // . . . all other code of the original Msc Class
       
     public void draw(Graphics g)
     {
for (int i=0; i<numOfRbs; i++)
{ rbss[i].draw(g); } } }

 


[Contents] [Next] [Previous]