The integrated application of JavaScript and Java applets

Source: Internet
Author: User

Java is becoming more and more widely used in www because of its flexibility, and many web pages use Java to increase dynamic and interactive conversations with users. Java script and Java applets are most commonly used in www. Java script is fast to start, simple to write, easy to modify, and the combination of documents closely, but its function is slightly too simple; Java applets are powerful and flexible, but are written in a complex way and cannot be modified directly in the document. Therefore, if the combination of the two can be used to achieve good results.

Let me give you an example of how to use Java Script and Java applets in a Web page.

First of all, we write a Java applet, called HelloWorld1 Good (everyone to the HelloWorld must not be unfamiliar).

Helloworld1.java

import java.awt.*;
import java.applet.*;
public class HelloWorld1 extends Applet
{
public String text="Hello World!";//请注意此处的public
public void paint(Graphics g)
{g.drawString(text,20,20);}
}

Helloworld1.class will be generated after compiling (Don't tell me the program can't pass!) If compiling errors, check to see if the spelling is incorrect. )

Example.html

<body>
<script language="JavaScript">
<!--
function SetText()
{
document.app.text="世界你好!";
document.app.repaint();//也请注意此句.
}
//-->
</script>

A comprehensive example of Java script and Java applets <br>

<applet code="HelloWorld1.class" width="100" height="28" name="app">
</applet>
<form>
<input type="button" value="请点击这里" onclick="SetText()">
</form>
</body>

Opening example.html with the browser will appear with a "Hello world!" Java applet and a button "please click here". We'll click the button and you'll find "Hello world!" into "The World Hello". This shows that Java script has successfully changed the content of text in HelloWorld1.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.