java的applet
『壹』 java Applet怎麼運行
1.首先編寫java文件,如下:
import java.awt.*;
import java.applet.*;
public class Java_Graphics extends Applet {
public void paint(Graphics g) {
g.drawString("用Graphics寫字和畫圖的基本方法", 20,40);
g.drawOval(100, 100, 30, 30);
g.drawOval(200, 100, 40, 25);
g.drawLine(20, 140, 200,140);
g.drawRect(20, 160, 50, 80);
g.drawRoundRect(110, 160, 100, 100, 25, 18);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
javac Java_Graphics.java 編譯完成後生成 java_Graphics.class
這將是在瀏覽器中執行的程序(.class文件)
2.其次,編寫對應的Html文件:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>My First Java Applet</title>
</head>
<body>
Here's my First Java Applet:
<applet code= "Java_Graphics.class" width = "300" height = "300">
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
> 想來大家都知道,最重要的當然這句<applet code= "Java_Graphics.class" width = "300"
> height = "300">,載入了.class文件
1
2
3.瀏覽器解釋執行:
點擊html文件,你可以看到你想看到的效果,(paint()所畫)~~