首页 技术 正文
技术 2022年11月20日
0 收藏 884 点赞 3,542 浏览 2907 个字
package unit4;
import java.awt.Graphics;public interface Shape {
void drowme(Graphics g);
double area();
double length();
String getName();}
package unit4;import java.awt.Graphics;public class Point implements Shape{
int x,y;
Point (int x,int y){this.x=x;this.y=y;} public double area() {
// TODO Auto-generated method stub
return 0;
}
public void drowme(Graphics g) {
g.fillOval(x,y,5,5); }
public String getName() {
// TODO Auto-generated method stub
return "Point";
}
public double length() {
// TODO Auto-generated method stub
return 0;
}
}
package unit4;import java.awt.Graphics;public class Triangle implements Shape {
Point a,b,c;
public Triangle(Point aa,Point bb,Point cc) {
// TODO Auto-generated constructor stub
a=aa;
b=bb;
c=cc; } public double area() { double a_b=Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
double a_c=Math.sqrt((a.x-c.x)*(a.x-c.x)+(a.y-c.y)*(a.y-c.y));
double b_c=Math.sqrt((b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y));
double l=(a_b+a_c+b_c)/2;
double s=Math.sqrt((l-a_b)*(l-b_c)*(l-a_c)*l);
return s;
} public void drowme(Graphics g) {
g.drawLine(a.x,a.y,b.x,b.y);
g.drawLine(a.x,a.y,c.x,c.y);
g.drawLine(b.x,b.y,c.x,c.y); } public String getName() {
return "triangle";
} public double length() {
double a_b=Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
double a_c=Math.sqrt((a.x-c.x)*(a.x-c.x)+(a.y-c.y)*(a.y-c.y));
double b_c=Math.sqrt((b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y));
double l=(a_b+a_c+b_c);
return l;
}}
package unit4;import java.awt.Graphics;public class Circl implements Shape {    Point c;
int r;
public Circl(Point cc,int rr) {
c=cc;
r=rr;
}
public double area() {
return 3.14159*r*r;
} public void drowme(Graphics g) {
g.drawOval(c.x-r,c.y-r,2*r,2*r); } public String getName() {
return "circle";
} public double length() {
return 2*3.14159*r;
}}
package unit4;import java.awt.Graphics;public class Rect implements Shape{
Point a,b;
Rect(Point aa,Point bb){a=aa;b=bb;} public double area() { return (a.x-b.x)*(a.y-b.y);
} public void drowme(Graphics g) {
g.drawRect(a.x,a.y,b.x-a.x,b.y-a.y); } public String getName() {
return "rectangle";
} public double length() {
return (b.x-a.x)*2+(b.y-a.y)*2;
}}
package unit4;import java.applet.Applet;
import java.awt.Graphics;public class Shapetest extends Applet{
Shape[]myshapes=new Shape[5];
public void init() { Point a0=new Point(50,50);
Point a1 = new Point(24,24);
Point a2=new Point(100,200);
Point a3 = new Point(200,120);
myshapes[0]=a0;
myshapes[1]=new Triangle(a1,a2,a3);
myshapes[2]=new Circl(a2,50);
myshapes[3]=new Circl(a3,100);
myshapes[4]=new Rect(new Point(100,100),new Point(200,200)); }
public void paint(Graphics g){
for(int i=0;i<myshapes.length;i++){
myshapes[i].drowme(g);
System.out.println(myshapes[i].getName()+": area: "+myshapes[i].area()+", length: "+myshapes[i].length());
}
}}

这里可以直接在eclipse上运行位applet,但是,我发现一个严重的问题,我没法部署网站,哎,先不管了,以后用到了在慢慢调吧。

每次都要费老大劲配置。我日。。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<applet code="shapetest.class" width=400 height=400>
</applet></body>
</html>

理论上,配置成功可以在网页上启动小程序的。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,961
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,485
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,330
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,113
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,746
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,780