// From Lay Networks.com import java.awt.*; class RouteTable extends Panel { RouteTable() { tab = new TextField[7][7]; setLayout(new GridLayout(8, 8, 3, 0)); add(topic = new Label("Table:")); for(int i = 0; i < 7; i++) { alpha = "" + (char)(97 + i); add(new Label(alpha)); } for(int j = 0; j < 7; j++) { alpha = "" + (char)(97 + j); add(new Label(alpha)); for(int k = 0; k < 7; k++) { add(tab[j][k] = new TextField("N/A")); tab[j][k].setEditable(false); } } } public void setTable(int i, int j, int k, int l) { String s = ""; if(i != j && k != 0) s = "" + k + "," + FindHop(l); else if(i != j && k == 0) s = "inf"; else if(i == j) s = "-"; tab[i][j].setText(s); } public void setColor(int i, int j, Color color) { tab[i][j].setBackground(color); } public void resetColor(int i, int j) { tab[i][j].setBackground(Color.lightGray); } public void resetAllColor() { for(int i = 0; i < 7; i++) { for(int j = 0; j < 7; j++) tab[i][j].setBackground(Color.lightGray); } } public void setDefault() { for(int i = 0; i < 7; i++) { for(int j = 0; j < 7; j++) tab[i][j].setText("N/A"); } } public String FindHop(int i) { String s = ""; switch(i) { case 0: // '\0' s = "A"; break; case 1: // '\001' s = "B"; break; case 2: // '\002' s = "C"; break; case 3: // '\003' s = "D"; break; case 4: // '\004' s = "E"; break; case 5: // '\005' s = "F"; break; case 6: // '\006' s = "G"; break; default: s = null; break; } return s; } Label topic; TextField tab[][]; String alpha; }