btcq.net
当前位置:首页 >> 用JAVA语言写一个二维平面图形(如长方形)的平移,旋... >>

用JAVA语言写一个二维平面图形(如长方形)的平移,旋...

import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; public class LX3_3 extends Applet { public void paint(Graphics g) { g.setColor(Color.red);//设置红颜色 g.drawOval(35,35,100,60);//画椭圆(圆心、宽和高) g.fillOval(200,

网上很多这样的.class Point2D{ int x, y; Point2D(){ } Point2D(int i,int j) { x=i; y=j; } void offset(int a, int b) { x=x+a; y=y+b; } void distance(Point2D a,Point2D b) { float m; m=(float)Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); System.out.print("二

class Rectangle{ double x1, y1, x2, y2; Rectangle(){ this(0,0,0,0); } Rectangle(double x1, double y1, double x2, double y2){ this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; } double getArea(){ return Math.abs((x1-x2)*(y1-y2))/2; } double getPemi(){

abstract class Shape{ abstract double area(); } class Circle extends Shape { private double r; private final double PI=3.14; public Circle(double r) { this.r = r; } @Override double area() { return PI*r*r; } } class Rectangle extends Shape { private double w

如果上半圆的半径和下面扇形的半径是一样的,那么沿虚线剪开图形,把剪下的部分绕半圆直径的两个端点,旋转90°,即可以得到一个长方形

逆时针旋转左边的图形

public class point{ private double x; private double y; point(){} point(double a,double b) { this.x=a; this.y=b; } public double getx() { return this.x; } public double gety() { return this.y; } public void setx(double a) { this.x=a; } public void sety(double b) { this.y=b; } }这样就可以了,我试了下能通过编译,你自己测试下试试吧

最简单的方法删除:用白色的线,在原位置按原大小再画一个.移动:删除旧的,再在新位置重新画一个

class Point{protected int x;protected int y;Point() { }Point( int x, int y ) { this.x = x; this.y = y; }Point( Point p ) { this.x = p.getx(); this.y = p.gety(); } public int getx() { return x; }public int gety() { return y; }public void setx( int x ) { this.x = x; } public void sety( int y ) { this.y = y; }}

网站首页 | 网站地图
All rights reserved Powered by www.btcq.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com