01: package net.xoetrope.samples.simple;
02:
03: import net.xoetrope.awt.XButton;
04: import net.xoetrope.awt.XEdit;
05: import net.xoetrope.awt.XPanel;
06: import net.xoetrope.xui.XPage;
07:
08: public class EventHandling extends XPage {
09: XEdit txtFirstname, txtSurname, txtAge, txtCarCost, txtDeposit,
10: txtAdvance;
11: XPanel pnlClientInfo, pnlFinancialInfo, pnlButtons;
12: XButton btnOK, btnCancel;
13:
14: public EventHandling() {
15: pnlClientInfo = (XPanel) componentFactory.addComponent(
16: XPage.PANEL, 10, 10, 210, 80);
17: pnlFinancialInfo = (XPanel) componentFactory.addComponent(
18: XPage.PANEL, 10, 100, 210, 80);
19: pnlButtons = (XPanel) componentFactory.addComponent(
20: XPage.PANEL, 10, 200, 210, 40);
21: pnlClientInfo.setDrawFrame(XPanel.BORDER_BEVEL);
22: pnlFinancialInfo.setDrawFrame(XPanel.BORDER_BEVEL);
23: pnlButtons.setDrawFrame(XPanel.BORDER_BEVEL);
24: componentFactory.setParentComponent(pnlClientInfo);
25: componentFactory.addComponent(XPage.LABEL, 5, 10, 90, 20,
26: "Firstname:", "prompt");
27: txtFirstname = (XEdit) componentFactory.addComponent(
28: XPage.EDIT, 100, 10, 100, 20, "Joe");
29: componentFactory.addComponent(XPage.LABEL, 5, 30, 90, 20,
30: "Surname:", "prompt");
31: txtSurname = (XEdit) componentFactory.addComponent(XPage.EDIT,
32: 100, 30, 100, 20, "Bloggs");
33: componentFactory.addComponent(XPage.LABEL, 5, 50, 90, 20,
34: "Age:", "prompt");
35: txtAge = (XEdit) componentFactory.addComponent(XPage.EDIT, 100,
36: 50, 100, 20, "38");
37:
38: componentFactory.setParentComponent(pnlFinancialInfo);
39: componentFactory.addComponent(XPage.LABEL, 5, 10, 90, 20,
40: "Car cost:", "prompt");
41: txtCarCost = (XEdit) componentFactory.addComponent(XPage.EDIT,
42: 100, 10, 100, 20, "10000.00");
43: componentFactory.addComponent(XPage.LABEL, 5, 30, 90, 20,
44: "Deposit:", "prompt");
45: txtDeposit = (XEdit) componentFactory.addComponent(XPage.EDIT,
46: 100, 30, 100, 20, "3000.00");
47: componentFactory.addComponent(XPage.LABEL, 5, 50, 90, 20,
48: "Advance:", "prompt");
49: txtAdvance = (XEdit) componentFactory.addComponent(XPage.EDIT,
50: 100, 50, 100, 20, "7000.00");
51: txtAdvance.setEnabled(false);
52:
53: componentFactory.setParentComponent(pnlButtons);
54: btnOK = (XButton) componentFactory.addComponent(XPage.BUTTON,
55: 40, 10, 60, 20, "Proceed");
56: btnCancel = (XButton) componentFactory.addComponent(
57: XPage.BUTTON, 110, 10, 60, 20, "Cancel", "BtnReverse");
58: addEvents();
59: }
60:
61: private void addEvents() {
62: addTextHandler(txtCarCost, "changeAdvance");
63: addTextHandler(txtDeposit, "changeAdvance");
64: addMouseHandler(btnOK, "proceed");
65: }
66:
67: public void changeAdvance() {
68: float cost = Float.valueOf(txtCarCost.getText()).floatValue();
69: float deposit = Float.valueOf(txtDeposit.getText())
70: .floatValue();
71: txtAdvance.setText(String.valueOf(cost - deposit));
72: }
73:
74: public void proceed() {
75: if (wasMouseClicked())
76: btnOK.setLabel("Clicked!");
77: }
78: }
|