FileDocCategorySizeDatePackage
NonModalYesNoDialog.javaAPI DocExample1353Sat Feb 22 16:53:34 GMT 1997None

NonModalYesNoDialog

public class NonModalYesNoDialog extends Dialog implements ActionListener

Fields Summary
private boolean
isAnswered
private boolean
isYes
Constructors Summary
NonModalYesNoDialog(Frame frame, String question)


	      
		super(frame, false /* non modal */);
		Label label = new Label(question);
		label.setFont( new Font("Dialog",Font.PLAIN,20) );
		add( "Center", label );

		Panel yn = new Panel();
		Button button = new Button("Yes");
		button.addActionListener( this );
		yn.add( button );
		button = new Button("No");
		button.addActionListener( this );
		yn.add( button );
		add("South", yn);
		pack();
	
Methods Summary
public synchronized voidactionPerformed(java.awt.event.ActionEvent e)

		isYes = e.getActionCommand().equals("Yes");
		isAnswered = true;
		notifyAll();
		dispose();
	
public synchronized booleananswer()

		while ( !isAnswered )
			try { wait(); } catch (InterruptedException e) { /* error */ }
		return isYes;
	
public static voidmain(java.lang.String[] s)

		Frame f = new Frame();
		f.add( "Center", new Label("I'm the application") );
		f.add( "South", new Button("You can press me?") );
		f.pack();
		f.show();

		NonModalYesNoDialog query = new NonModalYesNoDialog( f, "Do you love me?");
		query.show();
		if ( query.answer() == true )
			System.out.println("She loves me...");
		else
			System.out.println("She loves me not...");