/* * A GUI element, this is a grid of textboxs, designed to be used in * conjuction with the Matrix class, for input and output of values in * a matrix * * Author : Tom Kimber * */ import java.awt.* ; import java.util.* ; class TextFieldGridPanel extends Panel { private Vector v = new Vector( 4 , 4 ) ; private int num_cols ; private int num_rows ; public double getValue(int i , int j ) { int absPos ; absPos = i * num_cols + j ; TextField s = ( TextField )(v.elementAt( absPos ) ) ; Double d = new Double( s.getText() ) ; return d.doubleValue() ; } public void setValue( int i , int j , double x ) { int absPos ; absPos = i * num_cols + j ; TextField s = (TextField)(v.elementAt( absPos ) ) ; s.setText( "" + x ) ; } public void setValue( int i , int j , int x ) { int absPos ; absPos = i * num_cols + j ; TextField s = (TextField)(v.elementAt( absPos ) ) ; s.setText( "" + x ) ; } public TextFieldGridPanel( int n , int m ) { num_rows = n ; num_cols = m ; setLayout( new GridLayout( n , m ) ) ; for( int i = 0 ; i < n * m ; i++ ) { TextField tf = new TextField("0.0" , 5 ) ; tf.setBackground( Color.white ) ; v.addElement( tf ) ; } for( int i = 0 ; i < n * m ; i++ ) { TextField s = (TextField)(v.elementAt( i ) ) ; add( s ) ; } } }