import javax.swing.*; import java.awt.*; import java.util.*; public class LineBox { JTextField entry; JLabel title ; JPanel panel; public LineBox() { this.entry = new JTextField( 10 ); this.title = new JLabel( "text" ); this.panel = new JPanel(); this.setup( ); } public LineBox( String s ) { this.entry = new JTextField( 10 ); this.title = new JLabel( s ); this.panel = new JPanel(); this.setup( ); } private void setup( ) { FlowLayout arranger = new FlowLayout(); this.panel.setLayout( arranger ); this.panel.setPreferredSize( new Dimension( 300, 40 ) ); this.entry.setBackground( Color.WHITE ); this.panel.add( title ); this.panel.add( entry ); } public String getText() { String text = this.entry.getText(); return text; } public void setText( String s ) { this.entry.setText( s ); } public void setColor( Color c ) { this.panel.setBackground( c ); this.title.setBackground( c ); } public void addTo( Container c ) { c.add( this.panel ); } }