Wednesday, September 21, 2011

MyFirstApplet, run applet in HTML page

Create a file MyFirstApplet.java
import javax.swing.JApplet;
import java.awt.Graphics;

public class MyFirstApplet extends JApplet {

public void paint(Graphics g) {
g.drawString("Hello, Java-Buddy!", 50, 50);
}
}


Compile it in command prompt:
javac MyFirstApplet.java

Compile MyFirstApplet.java

Create a HTML file MyFirstApplet.html, embed MyFirstApplet.class inside.
<html>
<head>
<title> Java-Buddy </title>
</head>
<body>
<hr>
<applet code = "MyFirstApplet.class" width = 300 height = 300 >
</applet>
<hr/>
</body>
</html>


Open MyFirstApplet.html in browser.
MyFirstApplet, run applet in HTML page

No comments:

Post a Comment