Make your own free website on Tripod.com
package JGrid;
import java.awt.*;
import java.util.*;
import java.io.*;
import java.net.*;
import java.applet.*;
public class NetTableDemo extends Applet implements JGridCallback {
    Label msgLabel = new Label();
    JGrid2 grid;
    String[][] data;
    
public void init() {
    int colNum = new Integer(getParameter("columns")).intValue();
    int rowNum = new Integer(getParameter("rows")).intValue();
    String url = getParameter("dataURL");
		
    String[] headers = new String[colNum];
    for (int i=0; i<colNum; i++)
	headers[i] = "column "+i;
    grid = new JGrid2(headers,true,JGrid2.BOTH_BORDER);
    grid.setCallback(this);
    try {
        URL dataURL = new URL(url);
        BufferedReader reader = new BufferedReader(
            new InputStreamReader(dataURL.openStream()));
	data = new String[rowNum][colNum];
	for (int i=0; i<rowNum; i++) {
	    String line = reader.readLine();
	    StringTokenizer st = new StringTokenizer(line);
	    for (int j=0; j<colNum; j++) {
	        data[i][j] = st.nextToken();//new Double(st.nextToken()).toString();
	    }
	}
    } catch(Exception e) {
	e.printStackTrace();
    }
    grid.setContents(data);
	
    int[] colWidths = new int[colNum];
    for (int i=0; i<colNum; i++)
	colWidths[i] = 60;
    colWidths[2] = 100;
    grid.setColWidths(colWidths);
    setLayout(new BorderLayout());	
    add("Center",grid);
    add("South",msgLabel);
    show();
}
public void clickedCell (int row, int column,JGrid2 grid ) {
    msgLabel.setText("clicked on cell ("+row+","+column+")");
    JCell aCell = grid.getCell(column,row);
    if (aCell.httpAdd != null) {
        try {
            AppletContext ac = getAppletContext();
            ac.showDocument(new URL(aCell.httpAdd),"_blank");
        } catch(Exception e) {}
    }
}
public void clickedColumn (int column,JGrid2 grid ) {
    msgLabel.setText("clicked on column "+column);
}
}