Accessing Applets from within JavaScript : Applet Jar « Development « JavaScript DHTML






Accessing Applets from within JavaScript

//java source file
import java.applet.*;
import java.awt.*;

public class FancyText extends Applet {
 String text="I like Java!";


 public void paint(Graphics g) {
  g.drawString(text,30,30);
 }
 
 public void setText(String s) {
  text=s;
  repaint();
 }
}

//Loading and Accessing an Applet 
<head>
<TITLE>Accessing Applets</TITLE>
<SCRIPT LANGUAGE="JavaScript"><!--
function accessApplet() {
 setTimeout("changeText('I like JavaScript!')",2000)
 setTimeout("changeText('I like JavaScript and Java!')",4000)
 setTimeout("changeText('I like Java!')",6000)
 setTimeout("accessApplet()",8000)
}
function changeText(s) {
 window.document.fancyText.setText(s)
}
// --></SCRIPT>
</HEAD>
<BODY onLoad="accessApplet()">
<APPLET CODE="FancyText.class" NAME="fancyText"
 WIDTH=450 HEIGHT=150>
[The FancyText Applet]
</APPLET>



           
       








Related examples in the same category

1.Calling Java Methods
2.Using JavaScript in an Applet
3. Stopping and Starting an Applet
4. A More Fully Scripted Clock
5.Basic Signed Script Structure