01: package net.xoetrope.samples.controls;
02:
03: import java.awt.Frame;
04:
05: import net.xoetrope.awt.XButton;
06: import net.xoetrope.awt.XEdit;
07: import net.xoetrope.awt.XLabel;
08: import net.xoetrope.xui.XPage;
09: import net.xoetrope.xui.helper.BuddyHelper;
10: import net.xoetrope.xui.style.XStyleFactory;
11:
12: /**
13: * <p>Title: Xui</p>
14: * <p>Description: </p>
15: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003</p>
16: * <p>Company: Xoetrope Ltd.</p>
17: * @author not attributable
18: * @version 1.0
19: */
20:
21: public class DialogSample extends XPage {
22: XButton closeButton, occupationButton, nameButton;
23: XEdit txtFirstname, txtSurname;
24: XLabel lblOccupation;
25: Frame frame;
26: BuddyHelper buddy;
27:
28: public DialogSample() {
29: buddy = new BuddyHelper((XStyleFactory) componentFactory);
30:
31: frame = new Frame("Dialog Sample");
32: frame.setLayout(null);
33: frame.setSize(640, 580);
34: String desc = "This example shows how the XDialog control works. It can be invoked simply by calling the";
35: desc += " showMessage( msg ) function in the XPage class with the message you wish to display. Also the";
36: desc += " XDialog class can be extended to create a modal or non-modal dialog. Return values and object";
37: desc += " can be set and received by the subclass.";
38:
39: componentFactory.setParentComponent(this );
40: componentFactory.addComponent(XPage.LABEL, 10, 50, 530, 80,
41: desc);
42:
43: txtFirstname = (XEdit) buddy.addComponent(XPage.EDIT, 20, 250,
44: 130, 25, "Firstname", "Joe", null);
45: txtSurname = (XEdit) buddy.addComponent(XPage.EDIT, 20, 280,
46: 130, 25, "Surname", "Bloggs", null);
47: lblOccupation = (XLabel) buddy.addComponent(XPage.LABEL, 20,
48: 310, 130, 25, "Occupation", "", null);
49: occupationButton = (XButton) componentFactory.addComponent(
50: XPage.BUTTON, 230, 310, 30, 25, "...");
51: nameButton = (XButton) componentFactory.addComponent(
52: XPage.BUTTON, 10, 350, 100, 25, "Show Name");
53: closeButton = (XButton) componentFactory.addComponent(
54: XPage.BUTTON, 10, 540, 130, 25, "Close");
55: setHandlers();
56: setSize(frame.getSize());
57: frame.add(this );
58: frame.setVisible(true);
59: frame.show();
60: }
61:
62: public void setHandlers() {
63: addMouseHandler(closeButton, "Close");
64: addMouseHandler(occupationButton, "occupation");
65: addMouseHandler(nameButton, "showName");
66: }
67:
68: public void occupation() {
69: if (wasMouseClicked()) {
70: OccupationDlg dlg = new OccupationDlg(true, lblOccupation
71: .getText());
72: int ret = dlg.showDialog(getParent());
73: if (ret == 1) {
74: lblOccupation.setText((String) dlg.getReturnObject());
75: }
76: }
77: }
78:
79: public void showName() {
80: if (wasMouseClicked()) {
81: showMessage("Input error", "The name is "
82: + txtFirstname.getText() + " "
83: + txtSurname.getText());
84: }
85: }
86:
87: public static void main(String args[]) {
88: StyleSample styleSample = new StyleSample();
89: }
90:
91: public void Close() {
92: if (wasMouseClicked()) {
93: frame.setVisible(false);
94: }
95: }
96:
97: }
|