01: package net.ar.webonswing.tutorial;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05:
06: import javax.swing.*;
07:
08: import net.ar.webonswing.*;
09: import net.ar.webonswing.swing.components.validators.*;
10:
11: public class JCompareValidatorExample extends JDialog {
12: public JCompareValidatorExample() {
13: final JLabel label = new JLabel();
14:
15: JTextField component1 = new JTextField();
16: JTextField component2 = new JTextField();
17:
18: final JCompareValidator compareValidator = new JCompareValidator(
19: component1, "", "", false, component2,
20: JCompareValidator.Operation.equal,
21: JCompareValidator.Type.STRING);
22:
23: final JList operationList = new JList(new Object[] {
24: JCompareValidator.Operation.equal,
25: JCompareValidator.Operation.notEqual,
26: JCompareValidator.Operation.greaterThan,
27: JCompareValidator.Operation.greaterThanEqual,
28: JCompareValidator.Operation.lessThan,
29: JCompareValidator.Operation.lessThanEqual });
30:
31: JButton button = new JButton("Validate");
32: button.addActionListener(new ActionListener() {
33: public void actionPerformed(ActionEvent e) {
34: compareValidator
35: .setOperation((JCompareValidator.Operation) operationList
36: .getSelectedValue());
37:
38: if (compareValidator.doValidation())
39: label.setText("Page is Valid!");
40: else
41: label.setText("Not valid!");
42: }
43: });
44:
45: getContentPane().setLayout(new GridLayout(0, 1));
46:
47: getContentPane().add(label).setName("label1");
48: getContentPane().add(component1).setName("component1");
49: getContentPane().add(component2).setName("component2");
50: getContentPane().add(operationList).setName("operationList");
51: getContentPane().add(compareValidator).setName(
52: "compareValidator");
53: getContentPane().add(button).setName("button");
54:
55: getContentPane()
56: .setLayout(
57: WosFramework
58: .getPropagateTemplateLayoutByNameFor("JCompareValidatorExample.main"));
59: }
60: }
|