1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

what is JCompiler? with a sample[CODE]

Discussion in 'Web Development' started by omid128, Jul 13, 2010.

  1. omid128

    omid128 New Member

    Joined:
    Jul 9, 2010
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    What is JCompiler?

    This class considerably helps you to compile at the run time. For using it, you should inherit from the JCompiler class, then use the “addFileToWindowsRuntime”, create a new class. Afterward you can create an object from the created class by using JShooter.


    Code:
    ********************
    package mypackage;
    import org.j2sos.shine.jshooter.Application;
    import org.j2sos.shine.maplet.Maplet;
    public class Engine extends Maplet {
       public String name;
       public String body;
       public void learning() {
           try {
               new Memory().addMethod("public String " + name +
                   "() throws Exception {" + body + "}");
               out.println("Learned.");
           } catch (Exception e) {
               out.println(e.getMessage());
           }
       }
       public void request() {
           try {
               Application app = new Application();
               app.setObject(new Logic());
               out.println(app.invokeMethod(name));
           } catch (Exception e) {
               out.println(e);
           }
       }
    }
    ********************************************************************************
    package mypackage;
    public class Logic {
       public String hello() throws Exception {
           return "hello user!";
       }
    ********************************************************************************
    package mypackage;
    import org.j2sos.shine.util.JCompiler;
    public class Memory  extends JCompiler
    {
     public void addMethod(String body)throws Exception{
       new
    Memory().addCommandToClassBodyInWindowsRuntime("mypackage.Logic",body);
     }
    }
    **********************************Index.jsp***************************************
    <%@ page contentType="text/html;charset=windows-1252"%>
       <H1>Virtual Human</H1>
       <P>
         <a href="Learning.jsp">Learning.jsp</a>
       </P>
       <P>
         <a href="Request.jsp">Request.jsp</a>
       </P>
    **********************************Learning.jsp***************************************
    <%@ page contentType="text/html;charset=windows-1252"%>
       <H1>Virtual Human</H1>
       <form action="servlet/mypackage.Engine" method="get">
         <P>Method Name:
           <input type="text" name="name"/>
         </P>
         <P>Body:</P>
         <P>
           <textarea cols="40" rows="20" name="body"></textarea>
         </P>
         <P>
           <input type="submit" value="Submit"/>
         </P>
       </form>
    **********************************Request.jsp***************************************
    <%@ page contentType="text/html;charset=windows-1252"%>
       <H1>Virtual Human</H1>
       <form action="servlet/mypackage.Engine" method="get">
         <P>Method Name:
           <input type="text" name="name"/>
         </P>
         <P>
           <input type="submit" value="Submit"/>
         </P>
       </form>
     
    Last edited by a moderator: Jul 13, 2010

Share This Page