/* * A GUI widget: this is a label centered above a textbox, * desinged to be used for input of doubles * * Author : Tom Kimber * */ import java.awt.* ; public class LabelTextBox extends Panel { private Label lblBox = new Label("" , Label.CENTER ) ; public TextField txtBox = new TextField( "0.0" , 6 ) ; public LabelTextBox( String s ) { setLayout( new BorderLayout() ) ; setFont( new Font( "Monospaced" , Font.PLAIN , 12 ) ) ; txtBox.setBackground( Color.white ) ; lblBox.setText( s ) ; add( BorderLayout.NORTH , lblBox ) ; Panel pnlTextBox = new Panel() ; pnlTextBox.add( txtBox ) ; add( BorderLayout.CENTER , pnlTextBox ) ; } public void setText( String s ) { txtBox.setText( s ) ; } public double getValue( ) { Double d = new Double( txtBox.getText() ) ; return d.doubleValue() ; } }