NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
December 15, 2017, 07:39:54 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
"Wisdom is the harmony, healthy and happiness in life." ...Wisdom
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: how to use .java shared by other people and add it to Ejs?  (Read 9114 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
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?
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #1 on: January 05, 2010, 10:59:42 pm » posted from:Taipei,T\'ai-pei,Taiwan

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!)
I add my own sound java code (as an external jar library).
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #2 on: January 07, 2010, 05:18:46 pm » posted from:Singapore,,Singapore

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"? Grin
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #3 on: January 07, 2010, 09:18:24 pm » posted from:Singapore,,Singapore

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




* javvacerror.png (125.69 KB, 835x1045 - viewed 405 times.)

*** There are 1 more attached files. You need to login to acces it!
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #4 on: January 07, 2010, 09:43:46 pm » posted from:Singapore,,Singapore

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!


*** There are 1 more attached files. You need to login to acces it!
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #5 on: January 07, 2010, 09:56:08 pm » posted from:Singapore,,Singapore

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? Grin


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;
   ^


*** There are 1 more attached files. You need to login to acces it!
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #6 on: January 07, 2010, 10:37:10 pm » posted from:Taipei,T\'ai-pei,Taiwan

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.


*** There are 1 more attached files. You need to login to acces it!
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #7 on: January 07, 2010, 11:44:56 pm » posted from:Singapore,,Singapore

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 ; Huh
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


*** There are 1 more attached files. You need to login to acces it!
« Last Edit: January 07, 2010, 11:53:00 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #8 on: January 07, 2010, 11:51:16 pm » posted from:Taipei,T\'ai-pei,Taiwan

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();
Logged
Pages: [1]   Go Up
  Print  
"Wisdom is the harmony, healthy and happiness in life." ...Wisdom
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Java applets
Wave
tyree 1 25338 Last post March 19, 2004, 07:29:11 am
by Fu-Kwun Hwang
good people hwang
Wave
0 16983 Last post March 28, 2004, 12:08:12 pm
by
Problem with Java
Misc
Yves 3 9038 Last post February 12, 2008, 10:51:47 am
by Fu-Kwun Hwang
How to add Java Source: Calc3.java into EJS ?
Questions related to EJS
lookang 4 7986 Last post January 08, 2009, 09:53:44 pm
by lookang
I wish people are warm
Request for physics Simulations
hailan 0 2485 Last post March 21, 2011, 08:59:58 am
by hailan
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.076 seconds with 23 queries.since 2011/06/15