Thursday, 20 April 2017

MyFirstApplet, run applet in HTML page ~ foundjava

Create a file MyFirstApplet.java
?
1
2
3
4
5
6
7
8
9
10
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.

?
1
2
3
4
5
6
7
8
9
10
11
12
<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