Retrieving Information from a Dialog via Polling
import java.awt.*;
import java.awt.event.*;
public class YesNoDialog extends Dialog implements ActionListener {
private Button yes = new Button("Yes");
private Button no = new Button("No");
private String result = "uninitialized";
public YesNoDialog(Frame parent, String message) {
super(parent, true);
this.add(BorderLayout.CENTER, new Label(message));
Panel p = new Panel();
p.setLayout(new FlowLayout());
yes.addActionListener(this);
p.add(yes);
no.addActionListener(this);
p.add(no);
this.add(BorderLayout.SOUTH, p);
this.pack();
this.setLocation(100, 200);
this.pack();
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource == yes) result = "Yes";
else result = "No";
this.setVisible(false);
this.dispose();
}
public String getResult() {
return result;
}
}
Copyright
1997-1999, 2002, 2005, 2006 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified
August 20, 2006