01: package net.xoetrope.samples.controls;
02:
03: import java.awt.event.MouseEvent;
04:
05: import net.xoetrope.awt.XButton;
06: import net.xoetrope.awt.XComboBox;
07: import net.xoetrope.awt.XDialog;
08: import net.xoetrope.xui.XPage;
09:
10: /**
11: * <p>Title: Xui</p>
12: * <p>Description: </p>
13: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003</p>
14: * <p>Company: Xoetrope Ltd.</p>
15: * @author not attributable
16: * @version 1.0
17: */
18:
19: public class OccupationDlg extends XDialog {
20: XButton btnOK, btnCancel;
21: XComboBox cmbOccupations;
22: private String occupation;
23:
24: public OccupationDlg(boolean enabled, String occ) {
25: super (enabled, DEFAULT_PADDING);
26: occupation = occ;
27: setSize(400, 400);
28:
29: btnOK = (XButton) componentFactory.addComponent(XPage.BUTTON,
30: 10, 370, 72, 20, "OK");
31: btnCancel = (XButton) componentFactory.addComponent(
32: XPage.BUTTON, 90, 370, 72, 20, "Cancel");
33: cmbOccupations = (XComboBox) componentFactory.addComponent(
34: XPage.COMBO, 10, 100, 200, 20);
35: addOccupation("Programmer");
36: addOccupation("Teacher");
37: addOccupation("Milkman");
38: addOccupation("Postman");
39: addMouseHandler(btnOK, "closeDlg");
40: addMouseHandler(btnCancel, "cancel");
41: }
42:
43: private void addOccupation(String value) {
44: cmbOccupations.add(value);
45: if (value.equals(occupation))
46: cmbOccupations.select(cmbOccupations.getItemCount() - 1);
47: }
48:
49: public void closeDlg() {
50: MouseEvent evt = (MouseEvent) getCurrentEvent();
51: if (evt.getID() == evt.MOUSE_CLICKED) {
52: returnValue = 1;
53: returnObject = cmbOccupations.getSelectedItem();
54: setVisible(false);
55: }
56: }
57:
58: public void cancel() {
59: MouseEvent evt = (MouseEvent) getCurrentEvent();
60: if (evt.getID() == evt.MOUSE_CLICKED) {
61: returnValue = 0;
62: setVisible(false);
63: }
64: }
65: }
|