3 // ObservablesDialog.java
6 // Michael Kircher (mk1@cs.wustl.edu)
9 // Dialog for selecting Observables.
11 // ============================================================================
14 import java
.awt
.event
.*;
16 public class ObservablesDialog
extends Dialog
{
20 AnswerListener listener_
;
22 ObservablesDialog (DemoCore parent
,java
.util
.Enumeration enumeration
) {
24 super ((Frame
)parent
, "Select Observables", true);
26 this.setSize(400, 300);
27 setBounds (new Rectangle (50,50,400,300));
30 list_
.setFont ( new Font ("Helvetica", Font
.PLAIN
, 10));
31 list_
.setSize (200,200);
33 for (; enumeration
.hasMoreElements();) {
34 list_
.add ((String
)enumeration
.nextElement());
38 Button ok_button_
= new Button ("OK");
39 ok_button_
.setFont ( new Font ("DialogHelvetica", Font
.PLAIN
, 10));
40 Button cancel_button_
= new Button ("Cancel");
41 cancel_button_
.setFont ( new Font ("DialogHelvetica", Font
.PLAIN
, 10));
43 GridBagLayout gridbag_
= new GridBagLayout ();
44 GridBagConstraints constraints_
= new GridBagConstraints ();
46 constraints_
.fill
= GridBagConstraints
.BOTH
;
47 this.setLayout (gridbag_
);
49 constraints_
.weightx
= 1.0;
50 constraints_
.weighty
= 1.0;
51 constraints_
.gridwidth
= GridBagConstraints
.REMAINDER
;
52 gridbag_
.setConstraints (list_
, constraints_
);
55 constraints_
.weightx
= 1.0;
56 constraints_
.weighty
= 1.0;
57 constraints_
.gridwidth
= GridBagConstraints
.RELATIVE
;
58 constraints_
.fill
= GridBagConstraints
.NONE
;
59 gridbag_
.setConstraints (ok_button_
, constraints_
);
60 gridbag_
.setConstraints (cancel_button_
, constraints_
);
61 this.add (ok_button_
);
62 this.add (cancel_button_
);
64 ok_button_
.addActionListener (new ActionListener () {
65 public void actionPerformed (ActionEvent e
) {
67 String selected_
= ObservablesDialog
.this.list_
.getSelectedItem ();
68 if (selected_
!= null) {
69 System
.out
.println (">>>>> " + selected_
);
70 if (listener_
!= null) {
71 AnswerEvent ev
= new AnswerEvent (ObservablesDialog
.this, selected_
);
74 ObservablesDialog
.this.setVisible (false);
79 cancel_button_
.addActionListener (new ActionListener () {
80 public void actionPerformed (ActionEvent e
) {
81 ObservablesDialog
.this.setVisible (false);
86 public void addAnswerListener (AnswerListener al
) {