⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mycircle.java~76~

📁 Java画版程序。......................要求变态。
💻 JAVA~76~
字号:
package myshape;/** * Title: * Description: * Copyright:    Copyright (c) 2002 * Company: * @author * @version 1.0 */import java.awt.*;import java.math.*;public class MyCircle extends  MyShapeAdapter{ private MyPoint centerPoint,endPoint; private int radius; //private public MyCircle(){ } public MyCircle(MyPoint c,MyPoint e){ centerPoint=c; endPoint=e; } private Color color=super.defaultColor; private Color defaultColor=super.defaultColor; public  void setColor(Color c){   color=c; } public Color getColor(){   return color; } public void setDefaultColor(Color c){   defaultColor=c; } public Color getDefaultColor(){   return defaultColor; } public void paint(Graphics g){   g.setColor(color);   int x=centerPoint.getX()-endPoint.getX();   int y=centerPoint.getY()-endPoint.getY();   radius=(int)Math.sqrt(x*x+y*y); //  centerPoint.paint(g);  // endPoint.paint(g);   g.drawOval(centerPoint.getX()-radius,centerPoint.getY()-radius,radius*2,radius*2); } public MyShape getShape(){   MyCircle c=(MyCircle)this.clone();    c.centerPoint=(MyPoint)centerPoint.clone();    c.endPoint=(MyPoint)endPoint.clone();  // c.centerPoint.moveObject(centerPoint.getX()+14,centerPoint.getY()+4);  // c.endPoint.moveObject(endPoint.getX()+14,endPoint.getY()+4);   return c; } public void moveObject(MyShape s,int x,int y){  MyPoint p1=(MyPoint)s;  int tempx=centerPoint.getX()-x;  int tempy=centerPoint.getY()-y;  //System.out.print("sdfdksd  "+tempx);  int x1=centerPoint.getX()-endPoint.getX();  int y1=centerPoint.getY()-endPoint.getY();  radius=(int)Math.sqrt(x1*x1+y1*y1);  double tempr=Math.sqrt(tempx*tempx+tempy*tempy);  p1.moveObject((int)(centerPoint.getX()-tempx/tempr*radius),(int)(centerPoint.getY()-tempy/tempr*radius)); } public void moveObject(int x,int y){   if(movedPoint!=null){      if(!moveCircle){      // movedPoint.moveObject(x,y);      }      else{        int tempx=x-movedPoint.getX();        int tempy=y-movedPoint.getY();        movedPoint=new MyPoint(x,y);        centerPoint.moveObject(tempx+centerPoint.getX(),tempy+centerPoint.getY());        endPoint.moveObject(tempx+endPoint.getX(),tempy+endPoint.getY());     }   } } private MyPoint movedPoint; private boolean moveCircle=true; public boolean getChanged(){moveCircle=!moveCirlce;return moveCircle;} public boolean nearTo(int x,int y){ //centerPoint.attachToOthers=false; if(centerPoint.nearTo(x,y)){   //  centerPoint.attachToOthers=true;    // movedPoint=centerPoint;     moveCircle=false;     return false;  }  if(endPoint.nearTo(x,y)){    // movedPoint=endPoint;     moveCircle=false;     return false;  }  //centerPoint.attachToOthers=true;  int tempx=centerPoint.getX()-x;  int tempy=centerPoint.getY()-y;  tempx=(int)(Math.sqrt(tempx*tempx+tempy*tempy)-radius);   //System.out.print("OK  "+tempx);  if(tempx<8 &&tempx>-8){     movedPoint=new MyPoint(x,y);     moveCircle=true;     return true;  }  return false; } public MyPoint getPoint(){   return movedPoint; } public String toString(){ return  "Circle"; }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -