Learning JavaScript

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Learning JavaScript

David Webster
I have been trying to teach myself JavaScript by writing code embedded in
html and then loading that in Moszilla Firefox 3.6.8. But, I can't get it to
understand importPackage(java.awt). I just get an error message that says
"Error: importPackage is not defined". Does anyone know what the problem
coud be? The html is included below.

David Webster

<html>
 <head>
  <title>Run JavaScript File</title>
 </head>
 <body>
  <h1>Javascript File Test Begin</h1>
  <script language="JavaScript" type="text/JavaScript">
   importPackage(java.awt);
  </script>
  <h2>Javascript File Test End</h2>
 </body>
</html>
Reply | Threaded
Open this post in threaded view
|

Re: Learning JavaScript [OT]

Robert Baer
First, this would not seem to be a proper ImageJ post since it does mpt
specifically apply to using ImageJ.

That said, my guess is that you do not understand that JavaScript and Java
are two entirely different languages, albeit with similar syntax.  java.awt
is a collection of Java 2.0 user interface classes and has little to do with
the JavaScript engine built into Firefox.

HTH,

Rob

>I have been trying to teach myself JavaScript by writing code embedded in
> html and then loading that in Moszilla Firefox 3.6.8. But, I can't get it
> to
> understand importPackage(java.awt). I just get an error message that says
> "Error: importPackage is not defined". Does anyone know what the problem
> coud be? The html is included below.
>
> David Webster
>
> <html>
> <head>
>  <title>Run JavaScript File</title>
> </head>
> <body>
>  <h1>Javascript File Test Begin</h1>
>  <script language="JavaScript" type="text/JavaScript">
>   importPackage(java.awt);
>  </script>
>  <h2>Javascript File Test End</h2>
> </body>
> </html>
>
Reply | Threaded
Open this post in threaded view
|

Re: Learning JavaScript [OT]

David Webster
Rob,

My post wasn't OT , as I  was interested in seeing if I could use the ImageJ
and other APIs outside of ImageJ.

And, yes , I am aware that JavaScript and Java are different. I was trying
trying to use the importPackage/importClass feature which is supported by
ImageJ. But as Wayne pointed out, it isn't a feature of Firefox Javascript.

David

On Tue, Aug 10, 2010 at 12:21 PM, Robert Baer <[hidden email]> wrote:

> First, this would not seem to be a proper ImageJ post since it does mpt
> specifically apply to using ImageJ.
>
> That said, my guess is that you do not understand that JavaScript and Java
> are two entirely different languages, albeit with similar syntax.  java.awt
> is a collection of Java 2.0 user interface classes and has little to do with
> the JavaScript engine built into Firefox.
>
> HTH,
>
> Rob
>
> I have been trying to teach myself JavaScript by writing code embedded in
>> html and then loading that in Moszilla Firefox 3.6.8. But, I can't get it
>> to
>> understand importPackage(java.awt). I just get an error message that says
>> "Error: importPackage is not defined". Does anyone know what the problem
>> coud be? The html is included below.
>>
>> David Webster
>>
>> <html>
>> <head>
>>  <title>Run JavaScript File</title>
>> </head>
>> <body>
>>  <h1>Javascript File Test Begin</h1>
>>  <script language="JavaScript" type="text/JavaScript">
>>  importPackage(java.awt);
>>  </script>
>>  <h2>Javascript File Test End</h2>
>> </body>
>> </html>
>>
>>
Reply | Threaded
Open this post in threaded view
|

Re: Learning JavaScript

dscho
In reply to this post by David Webster
Hi David,

On Tue, 10 Aug 2010, David Webster wrote:

> I have been trying to teach myself JavaScript by writing code embedded
> in html and then loading that in Moszilla Firefox 3.6.8. But, I can't
> get it to understand importPackage(java.awt). I just get an error
> message that says "Error: importPackage is not defined". Does anyone
> know what the problem coud be? The html is included below.

There is quite some difference between Javascript as used in HTML than as
it is used in ImageJ. Not syntax-wise, but the way it is used.

As it happens, we have a very nice introduction on the Fiji Wiki:

        http://pacific.mpi-cbg.de/Javascript_Scripting

It assumes that you have basic knowledge of macro programming, though, as
it does not explain constructs such as conditionals or loops.

Ciao,
Johannes