FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Talking to javascript on the HTML page?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Talking to javascript on the HTML page?  (Read 2124 times)
Yorkshire_boy

Email
Talking to javascript on the HTML page?
« on: Oct 30th, 2002, 10:53am »

I apologise in advance for my shear lack of knowledge of the JAVA language (I am coming from a flash/javascript/asp background).
 
Can you speak to the HTML page from Proce55ing to say open new windows, images, pages etc? Either via some method of calling functions or some java (I am completely in the dark here) method that can open new pages directly from within its code.
 
Btw, keep up the good work, its all exciting stuff.
Tom
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: Talking to javascript on the HTML page?
« Reply #1 on: Oct 30th, 2002, 1:04pm »

Hi Tom,
 
You can use methods found in the Abstract Windowing Toolkit (AWT / java.awt.*) to do the functionalities that you would want to implement from the exported applet itself. AWT is automatically imported to the Java applet once you've exported it from Proce55ing. You can also use AWT methods as they are inherited while inside the P5 environment.
 
Please consult http://java.sun.com/j2se/1.3/docs/api/java/awt/package-summary.html for more info on AWT.
 
If the new windows you are referring to are Java windows, you'd need to know the concept of Frames.
 
Cheers!
 
fry


WWW
Re: Talking to javascript on the HTML page?
« Reply #2 on: Oct 30th, 2002, 5:14pm »

two answers.. the first is that there was an old technology from netscape called liveconnect that let javascript and java applets control one another, and all that stuff would work as well as it does in any other java applet, which is to say, not all that great. more info would be on netscape's site.
 
the second, more robust answer is that you can speak to html in very basic ways, using methods from the java 'Applet' class. the following example opens the p5 site when you press the 'a' key:
 
Code:
void setup() {
  size(200, 200);
}
 
void loop() { }
 
void keyPressed()
{
  if(key == 'a') {
    try {
      String url = "http:\u002f\u002fwww.Proce55ing.net";
      getAppletContext().showDocument(new URL(url));
 
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
  }
}

 
[ BUG NOTE: due to a parser error in 44, it interprets // as a comment, so everything after http:// was being removed.. sooo, that's what the \u002f is.. it's a temporary hack until i fix that code for the next release. sorry.. ]
 
the showDocument method will show a web page in the current window. you can also use showDocument to control a particular frame, i.e. showDocument("url", "frame_name") replacing frame_name as appropriate.. things like _self and _top work as well.
 
also note, however, that showDocument only works after having exported to applet.. since it requires that the code is being run within a web browser.  
 
hope that helps.
« Last Edit: Nov 19th, 2002, 6:50am by fry »  
Pages: 1 

« Previous topic | Next topic »