NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: lookang on January 05, 2010, 10:10:51 pm



Title: how to use .java shared by other people and add it to Ejs?
Post by: lookang on January 05, 2010, 10:10:51 pm
how to use .java shared by other people and add it to Ejs?

i tried to copy
http://www.huxtable.com/ip/blurring.html
http://www.huxtable.com/ip/ConvolveFilter.java

the contents of the .java file into the custom page of Ejs

there is error message

C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ejs_ImageTest\ImageTest.java:164: illegal start of type
  package com.jhlabs.image;  // > Custom.Lib Page 2:4
  ^
C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ejs_ImageTest\ImageTest.java:164: expected
  package com.jhlabs.image;  // > Custom.Lib Page 2:4
                          ^
C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ejs_ImageTest\ImageTest.java:165: illegal start of type
  import java.awt.*;  // > Custom.Lib Page 2:5
  ^
C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ejs_ImageTest\ImageTest.java:165: expected
  import java.awt.*;  // > Custom.Lib Page 2:5
                   ^
C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ejs_ImageTest\ImageTest.java:166: illegal start of type
  import java.awt.image.*;  // > Custom.Lib Page 2:6
  ^
C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ejs_ImageTest\ImageTest.java:166: expected
  import java.awt.image.*;  // > Custom.Lib Page 2:6
                         ^
C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ejs_ImageTest\ImageTest.java:167: illegal start of type
  import java.awt.geom.*;  // > Custom.Lib Page 2:7
  ^
C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ejs_ImageTest\ImageTest.java:167: expected
  import java.awt.geom.*;  // > Custom.Lib Page 2:7
                        ^
8 errors
Compilation produced an error!

is there any www that i can read to understand how to get the codes to work in Ejs?


Title: Re: how to use .java shared by other people and add it to Ejs?
Post by: Fu-Kwun Hwang on January 05, 2010, 10:59:42 pm
You need to compile the above code with JDK and then create a jar file with jar command.
Then you can add the jar file to the EJS.
Click the button at the top right corner, below the cross(close) button
(the same place where you can select "Add screen capture tools ..." options)
and you will find JAR Libraries in the Options and files tab,
 click check marker to select jar file to add to EJS library.
And add import statement (just one line above JAR Libraries.)
Then, you can use those functions defined in the jar anywhere inside EJS.

Please check out second post at EJS version of Fourier Synthesis (You can hear the sound,too!) (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1073.0)
I add my own sound java code (as an external jar library).


Title: Re: how to use .java shared by other people and add it to Ejs?
Post by: lookang on January 07, 2010, 05:18:46 pm
You need to compile the above code with JDK and then create a jar file with jar command.

Sorry, i tried to find youtube on this, but can U show how?

i look at my computer
C:\Program Files\Java\jdk1.6.0_17

which file do i click to "compile the above code with JDK"? ;D


Title: Re: how to use .java shared by other people and add it to Ejs?
Post by: lookang on January 07, 2010, 09:18:24 pm
i was reading this
http://www.skylit.com/javamethods/faqs/createjar.html

Creating a jar File in Command Prompt

   1. Start Command Prompt.
   2. Navigate to the folder that holds your class files:

      C:\>cd \mywork

   3. Set path to include JDK’s bin.  For example:

      C:\mywork> path c:\Program Files\Java\jdk1.5.0_09\bin;%path%  // done!

   4. Compile your class(es):

      C:\mywork> javac *.java // has error message

   5. Create a manifest file:

      C:\mywork> echo Main-Class: DanceStudio >manifest.txt

   6. Create a jar file:

      C:\mywork> jar cvfm DanceStudio.jar manifest.txt *.class

   7. Test your jar:

      C:\mywork> DanceStudio.jar

the error message is in the picture




Title: Re: how to use .java shared by other people and add it to Ejs?
Post by: lookang on January 07, 2010, 09:43:46 pm
in case some people is following the discussion
i found a way to do it

http://www.youtube.com/watch?v=FrJn4lK9ZK8&feature=related


i used http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.5.1-200909170800/eclipse-SDK-3.5.1-win32.zip
and followed the Youtube and it is compiled!


Title: Re: how to use .java shared by other people and add it to Ejs?
Post by: lookang on January 07, 2010, 09:56:08 pm
Then you can add the jar file to the EJS.
Click the button at the top right corner, below the cross(close) button
(the same place where you can select "Add screen capture tools ..." options)
and you will find JAR Libraries in the Options and files tab,
 click check marker to select jar file to add to EJS library.
And add import statement (just one line above JAR Libraries.)
Then, you can use those functions defined in the jar anywhere inside EJS.

I followed but with errors. Any tips? ;D


Generating simulation file ImageTestfkh...
C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ImageTestfkh.java:10: '.' expected
import ConvolveFilter;
                     ^
C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ImageTestfkhSimulation.java:10: '.' expected
import ConvolveFilter;
                     ^
C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ImageTestfkhView.java:10: '.' expected
import ConvolveFilter;
                     ^
C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ImageTestfkhApplet.java:10: '.' expected
import ConvolveFilter;
                     ^


Title: Re: how to use .java shared by other people and add it to Ejs?
Post by: Fu-Kwun Hwang on January 07, 2010, 10:37:10 pm
1. The jar (in your attached zip)  did not contain any compiled java class file.
2. The first java code is
Code:
package com.jhlabs.image;
It means that ConvolveFilter.java should be under com\jhlab\image directoory

Code:
public class ConvolveFilter extends AbstractBufferedImageOp {
It means that , AbstractBufferedImageOp.java is also required,
and AbstractBufferedImageOp.java need to be compiled before you can compile ConvolveFilter.java

When AbstractBufferedImageOp.class and AbstractBufferedImageOp.class are available.
Those files need to be packed into a jar file.

I found the filter.jar which contains all the filter at that web site.
Use it in the EJS ,remember to add import com.jhlabs.image.* in the option page ,
and it should work now.


Title: Re: how to use .java shared by other people and add it to Ejs?
Post by: lookang on January 07, 2010, 11:44:56 pm
1. The jar (in your attached zip)  did not contain any compiled java class file.
2. The first java code is
Code:
package com.jhlabs.image;
It means that ConvolveFilter.java should be under com\jhlab\image directoory

Code:
public class ConvolveFilter extends AbstractBufferedImageOp {
It means that , AbstractBufferedImageOp.java is also required,
and AbstractBufferedImageOp.java need to be compiled before you can compile ConvolveFilter.java

When AbstractBufferedImageOp.class and AbstractBufferedImageOp.class are available.
Those files need to be packed into a jar file.
This is new to me. Ok so the morale of the story is look for the jar file.
Ok i managed to import the filter.jar but how do i call the function ConvolveFilter () or how to know what to call it ; ???
i go see how u did it in the EJS version of Fourier Synthesis (You can hear the sound,too!) http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1073.0
Thanks!



I found the filter.jar which contains all the filter at that web site.
Use it in the EJS ,remember to add import com.jhlabs.image.* in the option page ,
and it should work now.
Yes, i also follow your lead n found it here
http://www.jhlabs.com/ip/filters/download.html
http://www.jhlabs.com/ip/filters/Filters.zip


Title: Re: how to use .java shared by other people and add it to Ejs?
Post by: Fu-Kwun Hwang on January 07, 2010, 11:51:16 pm
If you add the import in the option panel, then you can use it directly.
import tell java where to find the class file.
com.jhlabs.image.* will try to find all the class under com/jhlabs/image tree folder in the jar file.
Otherwise, you need to call it with com.jhlabs.image.ConvolveFilter();