package myClass;
import java.awt.*;
public class myGraphics {
double PI;
public void drawLine(Graphics g, int x0, int y0, int x, int y, String str, Color color,
Font font) {
Color oldcolor = g.getColor();
Font oldfont = g.getFont();
g.drawLine(x0, y0, x, y);
g.setColor(color);
g.setFont(font);
if(x > x0)
g.drawString(str, (x0 + x + 20) / 2, (y0 + y) / 2);
else
g.drawString(str, ((x0 + x) - 20) / 2, (y0 + y) / 2);
g.setColor(oldcolor);
g.setFont(oldfont);
}
public void drawAngleline(Graphics g, int x0, int y0, int len, double angle) {
int x = x0 + (int)((double)len * Math.cos(angle));
int y = y0 + (int)((double)len * Math.sin(angle));
g.drawLine(x0, y0, x, y);
}
public void drawArrow(Graphics g, int x0, int y0, int x, int y) {
Font font1 = new Font("Dialog", 1, 15);
drawArrow(g, x0, y0, x, y, " ", Color.black, font1);
}
public void drawArrow(Graphics g, int x0, int y0, int x, int y, String str, Color color,
Font font) {
int s = 8;
double a = PI / 12D;
Color oldcolor = g.getColor();
Font oldfont = g.getFont();
double angle = angleOfline(x0, y0, x, y);
g.drawLine(x0, y0, x, y);
if(angle <= PI / 2D) {
drawAngleline(g, x, y, s, (PI / 2D + angle) - a);
drawAngleline(g, x, y, s, PI / 2D + angle + a);
} else {
drawAngleline(g, x, y, s, angle - PI / 2D - a);
drawAngleline(g, x, y, s, (angle - PI / 2D) + a);
}
g.setColor(color);
g.setFont(font);
if(x > x0)
g.drawString(str, (x0 + x + 20) / 2, (y0 + y) / 2);
else
g.drawString(str, ((x0 + x) - 20) / 2, (y0 + y) / 2);
g.setColor(oldcolor);
g.setFont(oldfont);
}
public void drawArrow(Graphics g, int x0, int y0, int len, double angle) {
Font font1 = new Font("Dialog", 1, 15);
drawArrow(g, x0, y0, len, angle, " ", Color.black, font1);
}
public void drawArrow(Graphics g, int x0, int y0, int len, double angle, String str,
Color color, Font font) {
int s = 8;
double a = PI / 12D;
Color oldcolor = g.getColor();
Font oldfont = g.getFont();
drawAngleline(g, x0, y0, len, angle);
int x = x0 + (int)((double)len * Math.cos(angle));
int y = y0 + (int)((double)len * Math.sin(angle));
if(angle <= PI / 2D) {
drawAngleline(g, x, y, s, (PI / 2D + angle) - a);
drawAngleline(g, x, y, s, PI / 2D + angle + a);
g.setColor(color);
g.setFont(font);
g.drawString(str, x, y + 15);
} else {
drawAngleline(g, x, y, s, angle - PI / 2D - a);
drawAngleline(g, x, y, s, (angle - PI / 2D) + a);
g.setColor(color);
g.setFont(font);
g.drawString(str, x, y - 10);
}
g.setColor(oldcolor);
g.setFont(oldfont);
}
public void drawCircle(Graphics g, int x, int y, int r, int startAngle, int arcAngle) {
g.drawArc(x - r, y - r, 2 * r, 2 * r, startAngle, arcAngle);
}
public void drawMarrow(Graphics g, int x0, int y0, int len, double angle, String str,
Color color, Font font) {
int s = 8;
double a = PI / 12D;
Color oldcolor = g.getColor();
Font oldfont = g.getFont();
drawAnglemline(g, x0, y0, len, angle);
int x = x0 + (int)((double)len * Math.cos(angle));
int y = y0 + (int)((double)len * Math.sin(angle));
if(angle <= PI / 2D) {
drawAngleline(g, x, y, s, (PI / 2D + angle) - a);
drawAngleline(g, x, y, s, PI / 2D + angle + a);
g.setColor(color);
g.setFont(font);
g.drawString(str, x, y + 15);
} else {
drawAngleline(g, x, y, s, angle - PI / 2D - a);
drawAngleline(g, x, y, s, (angle - PI / 2D) + a);
g.setColor(color);
g.setFont(font);
g.drawString(str, x, y - 10);
}
g.setColor(oldcolor);
g.setFont(oldfont);
}
public void drawFillarrow(Graphics g, int x0, int y0, double angle) {
int s = 10;
int x[] = new int[3];
int y[] = new int[3];
double a = PI / 12D;
Color oldcolor = g.getColor();
g.setColor(Color.red);
x[0] = x0;
y[0] = y0;
if(angle <= PI / 2D) {
x[1] = x[0] + (int)((double)s * Math.cos((PI / 2D + angle) - a));
y[1] = y[0] + (int)((double)s * Math.sin((PI / 2D + angle) - a));
x[2] = x[0] + (int)((double)s * Math.cos(PI / 2D + angle + a));
y[2] = y[0] + (int)((double)s * Math.sin(PI / 2D + angle + a));
} else {
x[1] = x[0] + (int)((double)s * Math.cos(angle - PI / 2D - a));
y[1] = y[0] + (int)((double)s * Math.sin(angle - PI / 2D - a));
x[2] = x[0] + (int)((double)s * Math.cos((angle - PI / 2D) + a));
y[2] = y[0] + (int)((double)s * Math.sin((angle - PI / 2D) + a));
}
g.fillPolygon(x, y, 3);
g.setColor(oldcolor);
}
public void drawMline(Graphics g, int x0, int y0, int x, int y,double step) {
double m1 = Math.sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0));
int num = (int)(m1 / step);
int x1 = x0;
int y1 = y0;
for(int i = 0; i < num; i++) {
int x2 = x0 + (int)Math.round((double)(step * (i + 1) * (x - x0)) / m1);
int y2 = y0 + (int)Math.round((double)(step * (i + 1) * (y - y0)) / m1);
if(i % 2 == 0)
g.drawLine(x1, y1, x2, y2);
x1 = x2;
y1 = y2;
}
}
public void drawAnglemline(Graphics g, int x0, int y0, int len, double angle) {
int x = x0 + (int)((double)len * Math.cos(angle));
int y = y0 + (int)((double)len * Math.sin(angle));
// drawMline(g, x0, y0, x, y);
}
public double angleOfline(int x0, int y0, int x, int y) {
double s = Math.sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0));
double angle = Math.acos((double)(x - x0) / s);
if(y >= y0)
return angle;
else
return PI - angle;
}
public double angleOfoval(int x, int y, int x0, int y0, int a, int b) {
double s = Math.sqrt(Math.pow(b, 4D) * (double)(x - x0) * (double)(x - x0) + Math.pow(a, 4D) * (double)(y - y0) * (double)(y - y0));
double angle = Math.acos((double)(a * a * (y - y0)) / s);
if(x >= x0)
return PI - angle;
else
return angle;
}
public myGraphics() {
PI = 6.2831852000000001D;
}
public void fillCircle(Graphics g, int x0, int y0, int r, Color color) {
Color oldcolor = g.getColor();
g.setColor(color);
g.fillArc(x0 - r, y0 - r, 2 * r, 2 * r, 0, 360);
g.setColor(oldcolor);
}
public void fillCircle(Graphics g, int x0, int y0,int l, int r, Color color1,Color color2,double angle) {
Color oldcolor = g.getColor();
int x1=x0-(int)(r+l*Math.cos(angle));
int y1=y0-(int)(r+l*Math.sin(angle));
g.setColor(color1);
g.fillOval(x1,y1,2*r,2*r);
g.setColor(oldcolor);
}
public void Bar(Graphics g,int x,int y,int w,int h,int type)
{
if (type==0)
g.setColor(Color.white);
if (type==1)
g.setColor(Color.black);
g.drawLine(x,y,x+w,y);
g.drawLine(x,y,x,y+h);
if (type==1)
g.setColor(Color.white);
if (type==0)
g.setColor(Color.black);
g.drawLine(x+w,y,x+w,y+h);
g.draw
没有合适的资源?快使用搜索试试~ 我知道了~
Java-yan.rar_applet
共46个文件
class:10个
java:10个
vjp:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 81 浏览量
2022-09-23
07:46:16
上传
评论
收藏 68KB RAR 举报
温馨提示
几个Java Applet小程序的例子,很有启发意义。
资源推荐
资源详情
资源评论
收起资源包目录
Java-yan.rar (46个子文件)
生命游戏
Life.suo 5KB
Life.sln 505B
myClass
myGraphics.class 11KB
myGraphics.java 13KB
Applet1.class 5KB
codebase.dat 66B
Applet1.java 4KB
Life.vjp 4KB
Page1.htm 435B
付里叶变换
myClass
myGraphics.class 10KB
myGraphics.java 12KB
yyj.suo 5KB
yyj.sln 503B
Applet1.class 5KB
codebase.dat 68B
Applet1.java 4KB
yyj.vjp 4KB
Page1.htm 435B
混沌分叉
myClass
myGraphics.class 10KB
myGraphics.java 12KB
chaos2.sln 509B
Applet1.class 5KB
codebase.dat 66B
chaos2.vjp 4KB
chaos2.suo 5KB
Applet1.java 3KB
Page1.htm 496B
透镜起付氏变换作用
myClass
myGraphics.class 11KB
myGraphics.java 13KB
mirror-ft.vjp 4KB
mirror-ft.sln 515B
Applet1.class 5KB
codebase.dat 76B
Applet1.java 4KB
mirror-ft.suo 5KB
Page1.htm 436B
www.pudn.com.txt 218B
洛伦兹吸引子
myClass
myGraphics.class 11KB
myGraphics.java 13KB
Lorenz.vjp 4KB
Lorenz.sln 509B
Applet1.class 5KB
codebase.dat 70B
Applet1.java 3KB
Lorenz.suo 5KB
Page1.htm 435B
共 46 条
- 1
资源评论
weixin_42653672
- 粉丝: 89
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功