2 * Generic framework for prompting users for stuff
7 public class promptWindow extends Frame {
8 public static int ONE_FIELD=1, TWO_FIELD=2, YES_NO=3;
13 TextField text1, text2;
19 public promptWindow( promptCmd cmd ) {
20 super( cmd.getTitle() );
24 go = stop = yes = no = null;
27 setLayout( new BorderLayout() );
28 add( "North", new Label( cmd.getPrompt() ) );
30 Panel p = new Panel();
32 if( cmd.getType() != YES_NO ) {
33 PairPanel pp = new PairPanel();
35 pp.addLeft( new Label( cmd.firstPrompt() ) );
36 pp.addRight( text1 = new TextField(10) );
37 if( !cmd.firstEcho() )
38 text1.setEchoCharacter( '.' );
39 if( cmd.getType() == TWO_FIELD ) {
40 pp.addLeft( new Label( cmd.secondPrompt() ) );
41 pp.addRight( text2 = new TextField(10) );
42 if( cmd.secondEcho() )
43 text2.setEchoCharacter( '.' );
46 p.add( go = new Button( cmd.affirm() ) );
47 p.add( stop = new Button( cmd.negate() ) );
50 p.add( yes = new Button( "Yes" ) );
51 p.add( no = new Button( "No" ) );
59 public boolean handleEvent( Event e ) {
60 if( e.id == Event.WINDOW_DESTROY ) {
63 return super.handleEvent( e );
66 public boolean action( Event e, Object o ) {
67 if( (e.target == stop) || (e.target == no) ) {
70 } else if (e.target == yes ) {
72 if( cmd.getType() == YES_NO )
75 } else if( e.target == go ) {
76 String t1 = null, t2 = null;
78 if( text1 != null ) t1 = text1.getText();
79 else if( text2 != null ) t2 = text2.getText();
82 if( cmd.getType() == ONE_FIELD )
85 cmd.two_fields( t1, t2 );
87 return super.action( e, o );