How to pass a value from Java Applet code to HTML page
-
I have an application where I need to send the values from java applet code to html page. Please help me to send the values from java code to HTML page(may be using javascript) My java code is,
public class Calc extends Applet
{public int tot = 0; public void paint(Graphics g) { int M1 = Integer.parseInt(this.getParameter("m1")); int M2 = Integer.parseInt(this.getParameter("m2")); int M3 = Integer.parseInt(this.getParameter("m3")); int M4 = Integer.parseInt(this.getParameter("m4")); int M5 = Integer.parseInt(this.getParameter("m5")); int M6 = Integer.parseInt(this.getParameter("m6")); tot=M1+M2+M3+M4+M5+M6; this.setParameter("tot",Integer.toString(tot)); g.drawString(Integer.toString(tot), 10, 10); }
}
-
I have an application where I need to send the values from java applet code to html page. Please help me to send the values from java code to HTML page(may be using javascript) My java code is,
public class Calc extends Applet
{public int tot = 0; public void paint(Graphics g) { int M1 = Integer.parseInt(this.getParameter("m1")); int M2 = Integer.parseInt(this.getParameter("m2")); int M3 = Integer.parseInt(this.getParameter("m3")); int M4 = Integer.parseInt(this.getParameter("m4")); int M5 = Integer.parseInt(this.getParameter("m5")); int M6 = Integer.parseInt(this.getParameter("m6")); tot=M1+M2+M3+M4+M5+M6; this.setParameter("tot",Integer.toString(tot)); g.drawString(Integer.toString(tot), 10, 10); }
}
The sample HTML file The listing below shows the source code for the sample HTML file we created for this article, including the applet tag shown.We name this file AppletParameterTest.html.
Java applet example - Passing applet parameters to Java applets
The ParamTest.java file So far we've seen to create the HTML code that (1) invokes a Java applet using an applet tag, and (2) passes parameters to the applet. Next, let's look at the Java applet code needed to read the parameters being passed to it. The next listing shows the Java code for the ParamTest.java file.
import java.applet.*;
import java.awt.*;public class AppletParameterTest extends Applet {
public void paint(Graphics g) {
String myFont = getParameter("font"); String myString = getParameter("string"); int mySize = Integer.parseInt(getParameter("size")); Font f = new Font(myFont, Font.BOLD, mySize); g.setFont(f); g.setColor(Color.red); g.drawString(myString, 20, 20);
}
}