正在加载图片...
package shapes; import java.awt.*; public class TriangleNew extends Triangle implements DrawShapes { int[ xCoords; /新类添加的属性,绘制三角形的x坐标点 int yCoords; /新类添加的属性,绘制三角形的y坐标点 public TriangleNew(int a, int b, int c) { super(a,b,c); //调用父类 public void setCoords(int xo, int yo)计算坐标的方法 xCoords=new int[3]; /初始亻 yCoords=new int[3]; 初始 int x1=x0, y1=y0; /设定第1个点的x、y坐标 int x2=x1+sidea, y2=y1; 计算第2个点的x、y坐标 int temp=sidea*sidea+sideb*sideb-sidec*sidec; public void drawGraphics)实 int temp2=(int)temp/(2sidea);/余弦公式 int x3=x2-temp2; setCoords(260,300计算三角形的3inty3y2-(int)mathh.sqrtsidebsideb--temp2*temp2) g.drawPolygon(xCoords, yCoords, 3); xCoords[]=X1; yCoords[0]=y1; public void fillcolor(Graphics g, Color xCoords[1]=x2; yCoords[1]=y2; xCoords[2]=; g.setColor() yCoords[2]=y3; g.fillPolygon(xCoords, yCoords, 3);/Java面向对象程序设计 3.6.2 接口的实现
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有