Object Support

Access Existing Objects

    ;; Create the widgets
    (defglobal ?*f* = (new java.awt.Frame "Button Demo"))
    (defglobal ?*b* = (new java.awt.Button "Hello"))

    ;; Define the deffunction
    (deffunction say-hello "Unconditionally print a message" (?evt)
        (printout t "Hello, World!" crlf))

    ;; Connect the deffunction to the button
    (?*b* addActionListener
        (new jess.awt.ActionListener say-hello (engine)))

    ;; Assemble and display the GUI
    (?*f* add ?*b*)
    (?*f* pack)
    (set ?*f* visible TRUE)

AWT Examples

  1. hello.clp
  2. draw.clp
  3. frame.clp
  4. swing.clp

Demos

  1. deck.clp (clips source)
  2. poker.clp (clips source)

    Java files needed:Card.java Cards.java

Access member variables of Java objects

    (bind ?pt (new java.awt.Point))
    (set-member ?pt x 37)
    (set-member ?pt y 42)
    (get-member ?pt x)

Access static members of Java classes

    (get-member System out)

Defclass

tell Jess to generate a deftemplate representing a category of Beans.

Definstance

put one specific Bean onto knowlege base.

the representation can be :

  1. static
    updated only when reset command is issued

    Example

    Java program:

        public class NameBean
        {
            private String name = "Bob";
            public String getName() { return name; }
            public void setName(String s) { name = s; }
        }
    

    Jess program:
        (defclass simple NameBean)
        (ppdeftemplate simple)
    
        (bind ?sb (new NameBean))
        (definstance simple ?sb static)
        (facts)
        (call ?sb setName "Fred")
        (facts)
    

    Demo: name.clp

  2. dynamic
    updated every time a property of Bean changes

    Demo: dname.clp
    java source: DynamicBean.java
    jess source: dname.clp

Another Example

    Demo: vector.clp
    java source: Vector.java
    jess source: vector.clp

Deftemplate Inheritance

One deftemplate construct can be defined in terms of another using extends, for example,
(deftemplate automobile "A specific car."
    (slot make)
    (slot model)
    (slot year (type INTEGER))
    (slot color (default white)))

(deftemplate used-auto extends automobile
    (slot mileage)
    (slot blue-book-value)
    (multislot owners))

I/O Routers

By default, Jess's standard routers are connected to Java's standard streams. However, you can connect the t router to any Java java.io.Reader and java.io.Writer objects, or add routers of your own using
    public void addInputRouter(String s, Reader is, boolean consoleLike)
    public void addOutputRouter(String s, Writer os)

Introduction to Servlets

Examples:
  1. WelcomeServlet ( source )
  2. WelcomeServlet2, using query string for input ( source )
  3. WelcomeServlet3, using form input ( source )

JESS Servlets

Example 1: hard-wired file name

Example 2: file name specified in query string

Example 3: source URL specified in query string

Web Page Interface («Ø¸mºô­¶¤¶­±)

Reference

Previous Jess Introduction   Up TOC   Next Efficiency in Rule-based Languages