petite/src/wombat/scheme/libraries/MatrixAPI.java
public static void drawMatrix(String data) {
		// For the row and column indicies.
		class IndexLabel extends JLabel {
			private static final long serialVersionUID = -7749472183222490884L;
			public IndexLabel(String text) {
				super(text);
				setHorizontalAlignment(SwingConstants.CENTER);
			}
		}
		
		// For each of the actual cells.
		class DataLabel extends JLabel {
			private static final long serialVersionUID = -8188624620043747866L;
			public DataLabel(String text) {
				super(text);
				setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
				setHorizontalAlignment(SwingConstants.CENTER);
			}
		}
		
		// Scan one line at a time.
		Scanner s = new Scanner(data);
		
		// Get the size of the grid.
		int rows = Integer.parseInt(s.nextLine());
		int cols = Integer.parseInt(s.nextLine());
		
		// Create the grid, we'll put this in a JScrollPane later.
		JPanel grid = new JPanel();
		grid.setLayout(new GridLayout(rows + 1, cols + 1));
		grid.add(new JLabel());
		
		// Add an index across the top.
		for (int c = 0; c < cols; c++)
			grid.add(new IndexLabel("" + c));
		
		// Add each row number than a row of data.
		for (int r = 0; r < rows; r++) {
			grid.add(new IndexLabel("" + r));
			for (int c = 0; c < cols; c++)
				grid.add(new DataLabel(s.nextLine()));
		}
		
		// Clean up
		s.close();
		
		// Display the frame.
		JFrame matrixFrame = new JFrame("draw-matrix");
		matrixFrame.setSize(400, 400);
		matrixFrame.setLayout(new BorderLayout());
		matrixFrame.add(new JScrollPane(grid));
		matrixFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		matrixFrame.setVisible(true);
	}
/**
	 * Turn data into a matrix GUI.
	 * @param data Row number then column number, then row delimited data.
	 */
Turn data into a matrix GUI.
@param data Row number then column number, then row delimited data.
Turn data into a matrix GUI . @param data Row number then column number then row delimited data .
public static void drawMatrix(String data) {
		class IndexLabel extends JLabel {
			private static final long serialVersionUID = -7749472183222490884L;
			public IndexLabel(String text) {
				super(text);
				setHorizontalAlignment(SwingConstants.CENTER);
			}
		}
		class DataLabel extends JLabel {
			private static final long serialVersionUID = -8188624620043747866L;
			public DataLabel(String text) {
				super(text);
				setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
				setHorizontalAlignment(SwingConstants.CENTER);
			}
		}
		Scanner s = new Scanner(data);
		int rows = Integer.parseInt(s.nextLine());
		int cols = Integer.parseInt(s.nextLine());
		JPanel grid = new JPanel();
		grid.setLayout(new GridLayout(rows + 1, cols + 1));
		grid.add(new JLabel());
		for (int c = 0; c < cols; c++)
			grid.add(new IndexLabel("" + c));
		for (int r = 0; r < rows; r++) {
			grid.add(new IndexLabel("" + r));
			for (int c = 0; c < cols; c++)
				grid.add(new DataLabel(s.nextLine()));
		}
		s.close();
		JFrame matrixFrame = new JFrame("draw-matrix");
		matrixFrame.setSize(400, 400);
		matrixFrame.setLayout(new BorderLayout());
		matrixFrame.add(new JScrollPane(grid));
		matrixFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		matrixFrame.setVisible(true);
	}
public static void drawMatrix ( String data ) { class IndexLabel extends JLabel { private static final long serialVersionUID = - 7749472183222490884L ; public IndexLabel ( String text ) { super ( text ) ; setHorizontalAlignment ( SwingConstants . CENTER ) ; } } class DataLabel extends JLabel { private static final long serialVersionUID = - 8188624620043747866L ; public DataLabel ( String text ) { super ( text ) ; setBorder ( BorderFactory . createBevelBorder ( BevelBorder . LOWERED ) ) ; setHorizontalAlignment ( SwingConstants . CENTER ) ; } } Scanner s = new Scanner ( data ) ; int rows = Integer . parseInt ( s . nextLine ( ) ) ; int cols = Integer . parseInt ( s . nextLine ( ) ) ; JPanel grid = new JPanel ( ) ; grid . setLayout ( new GridLayout ( rows + 1 , cols + 1 ) ) ; grid . add ( new JLabel ( ) ) ; for ( int c = 0 ; c < cols ; c ++ ) grid . add ( new IndexLabel ( "" + c ) ) ; for ( int r = 0 ; r < rows ; r ++ ) { grid . add ( new IndexLabel ( "" + r ) ) ; for ( int c = 0 ; c < cols ; c ++ ) grid . add ( new DataLabel ( s . nextLine ( ) ) ) ; } s . close ( ) ; JFrame matrixFrame = new JFrame ( "draw-matrix" ) ; matrixFrame . setSize ( 400 , 400 ) ; matrixFrame . setLayout ( new BorderLayout ( ) ) ; matrixFrame . add ( new JScrollPane ( grid ) ) ; matrixFrame . setDefaultCloseOperation ( JFrame . DISPOSE_ON_CLOSE ) ; matrixFrame . setVisible ( true ) ; }
Turn data into a matrix GUI.
Turn data into a matrix GUI .
// For the row and column indicies. // For each of the actual cells. // Scan one line at a time. // Get the size of the grid. // Create the grid, we'll put this in a JScrollPane later. // Add an index across the top. // Add each row number than a row of data. // Clean up // Display the frame.