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()所画)~~