扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
1、楼主你的内部类用错了,内部类不能放到方法里面,特别是构造器里面,要移出去,与
创新互联服务紧随时代发展步伐,进行技术革新和技术进步,经过十年的发展和积累,已经汇集了一批资深网站策划师、设计师、专业的网站实施团队以及高素质售后服务人员,并且完全形成了一套成熟的业务流程,能够完全依照客户要求对网站进行成都做网站、成都网站建设、建设、维护、更新和改版,实现客户网站对外宣传展示的首要目的,并为客户企业品牌互联网化提供全面的解决方案。
public JavaApplication28()同级
2、JPanel jPanel1=new JPanel();楼主你新建面板的时候用的不是你自建的面板类而是系统的面板
类,你自己的面板类根本就没用上,当然画不出来了
3、不管是不是内部类,类名首字母最好大写
4、将JPanel jPanel1=new JPanel();换为jPanel1 jPanel1=new jPanel1();,但是jPanel1 jPanel1
的这种写法很容易出错,最好改了
下面是我改完的代码,我已经将类名首字母大写了
import java.awt.*;
import javax.swing.*;
public class JavaApplication28 extends JFrame {
public JavaApplication28(){
JPanel1 jPanel1=new JPanel1();
Container content=getContentPane();
this.setVisible(true);
this.setSize(400, 400);
content.add(jPanel1);
jPanel1.setBackground(Color.red);
jPanel1.setForeground(Color.WHITE);
}
class JPanel1 extends JPanel{
public void paint(Graphics g){
super.paint(g);
//g.drawO
g.drawOval(10,0,30,10);
}
}
public static void main(String args[]){
JavaApplication28 j=new JavaApplication28();
}
}
已经可以画出园了
public class Circle_J {
public static void main(String[] args){
System.out.println("请依次输入第一个圆的圆心坐标x和y以及半径,彼此以空格隔开");
Scanner read = new Scanner(System.in);
String string1 = String.valueOf(read.nextLine());
String[] data1 = string1.split(" ");
System.out.println("请依次输入第二个圆的圆心坐标x和y以及半径,彼此以空格隔开");
String string2 = String.valueOf(read.nextLine());
String[] data2 = string2.split(" ");
double xDistance = Math.abs(Integer.parseInt(data2[0])-Integer.parseInt(data1[0]));
double yDistance = Math.abs(Integer.parseInt(data2[1])-Integer.parseInt(data1[1]));
double rCount =Integer.parseInt(data2[2]) +Integer.parseInt(data1[2]);
if((Math.pow(xDistance,2)+Math.pow(xDistance,2))=(Math.pow(rCount,2)))
{
System.out.println(Math.pow(rCount,2));
System.out.println("相交");
}else{
System.out.println("不相交");
}
read.close();
}
}
两个外切正方形如上,A、C分别代表左上的坐标点,B、D代表左下的坐标点。E,F代表两个点的圆心。
Coordinate A;B;C:D;
Coordinate E = (A+B)/2;
Coordinate F = (C+D)/2;
double distanceEF = E.distance.F;
RadiusE= A.distance.B/2/sqrt(2);
RadiusF= C.distance.D/2/sqrt(2);
if(distanceEF==RadiusE + RadiusF)
cout"相切"endl;
if(distanceEF abs(RadiusE - RadiusF) distanceEF (RadiusE + RadiusF))
cout"相交"endl;
大概就是上面这样子,具体代码实现要结合平台进行一下调整,全部是手打的,麻烦采纳给个好评哦,好人一生平安
在同一平面中:A圆的半径为x,B圆的半径为y,两圆圆心距离为z。如果x+y
z,
则两圆不相交;如果x-y
z
x+y,则两圆相交;如果|x-y|
z,则两圆内含。LZ有空看看初中数学吧
boolean isIntersecting(Circle c){
return Math.sqrt((_x-c._x)*(_x-c._x)+(_y-c._y)*(_y-c._y))=_r+c._r;
}
double sharedArea(Circle c){
double alpha,area;
double d=Math.sqrt((_x-c._x)*(_x-c._x)+(_y-c._y)*(_y-c._y));//两圆心距离
if(d_r+c._r){
return 0;
}
alpha=Math.acos((d*d+_r*_r-c._r*c._r)/(2*d*_r));//余弦定理取得相交弧所对本圆的圆心角
area=alpha*_r*_r;//本圆扇形面积
alpha=Math.acos((d*d+c._r*c._r-_r*_r)/(2*d*c._r));//余弦定理取得相交弧所对另一圆的圆心角
area+=alpha*c._r*c._r;//另一圆的扇形面积
double s=(d+_r+c._r)/2;//海伦公式之s
area-=Math.sqrt(s*(s-d)*(s-_r)*(s-c._r))*2;//两扇形面积减去两三角形面积即为交集
return area;
}
public class Cycle {
private double x = 0;//圆心横坐标
private double y = 0;//圆心纵坐标
private double r = 0;//圆心半径
public static void main(String[] args) {
String relation = "";
Cycle c = new Cycle(0,0,1);
//相交 外切 内切 相离
Cycle c_xiangJiao = new Cycle(3,4,5);
Cycle c_waiQie = new Cycle(3,4,4);
Cycle c_neiQie = new Cycle(3,4,6);
Cycle c_xiangLi = new Cycle(3,4,2);
relation = c.relationWithOtherCycle(c_xiangJiao);
System.out.println("c c_xiangJiao relationShip :"+relation);
relation = c.relationWithOtherCycle(c_xiangLi);
System.out.println("c c_xiangLi relationShip :"+relation);
relation = c.relationWithOtherCycle(c_neiQie);
System.out.println("c c_neiQie relationShip :"+relation);
relation = c.relationWithOtherCycle(c_waiQie);
System.out.println("c c_waiQie relationShip :"+relation);
}
public Cycle(double x, double y, double r) {
this.r = r;
this.x = x;
this.y = y;
}
public Cycle() {
}
public String relationWithOtherCycle(Cycle c){
String relation = ""; //相交 外切 内切 相离
double length = 0;// (x-x1)*(x-x1)+(y-y1)*(y-y1) 开平方
length = Math.sqrt((this.x-c.getX())*(this.x-c.getX())+(this.y-c.getY())*(this.y-c.getY()));
//System.out.println("length : "+length);
if(length(this.r+c.getR())){
relation = "相离";
}else if (length==(this.r+c.getR())){
relation = "外切";
}else if (length==Math.abs(this.r-c.getR())){
relation = "内切";
}else if (lengthMath.abs(this.r+c.getR())lengthMath.abs(this.r-c.getR())){
relation = "相交";
}
return relation;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getR() {
return r;
}
public void setR(double r) {
this.r = r;
}
}
//把测试程序写在Cycle的main方法里了
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流