JAVA圓與圓心代碼 java同心圓

請寫出用java代碼畫一個圓

靠,樓上的回答那么長啊,只要一個函數(shù),就是

站在用戶的角度思考問題,與客戶深入溝通,找到八公山網(wǎng)站設計與八公山網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都做網(wǎng)站、成都網(wǎng)站建設、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、國際域名空間、虛擬空間、企業(yè)郵箱。業(yè)務覆蓋八公山地區(qū)。

drawOval(int x,int y,int w,int h); 這是是畫橢圓形的函數(shù),但是它也可以畫圓形。

比如 drawOval(100,100,50,50); 就在坐標50,50畫一個直徑100的圓,只要把,最后的2個參數(shù)設成一樣就是一個圓。要畫直徑200的話,就把最后2個參數(shù)設成200,200 一切OK了

java 如何以圓心畫圓

包java.awt.Graphics

中的drawOval(int x,int y,int width,int height)方法可以畫圓。

x,y是坐標,圓心位置

width,height是圓的寬度和長度,他們相等的時候就是圓,不等就是橢圓。值就是半徑

急求Java代碼,定義一個Circle(圓類型)

public class Exam

{

public static void main(String[] args)

{

Circle c=new Circle(3,4,5);

System.out.printf("圓心:(%f,%f),半徑:%f,面積:%f",c.x,c.y,c.r,c.countArea());

}

}

class Circle

{

public Circle()

{

this(0,0,0);

}

public Circle(double x,double y,double r)

{

this.x=x;

this.y=y;

this.r=r;

}

public double countArea()

{

return Math.PI*r*r;

}

/*private*/public double x,y,r;

}

用java寫同心圓的程序,顯示不出來,程序顯示空白是怎么回事?以下是程序代碼。

這只是處理產(chǎn)生同心圓的方法,你只寫了方法卻沒有調(diào)用。就好比你吃飯,筷子是用來夾菜的,那么筷子就是這個處理方法,但是你沒有手,你說怎么夾菜?

用java求兩個圓關系的代碼,,求完整的,正確的源代碼,謝謝?。?/h2>

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);

//相交 外切 內(nèi)切 相離

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 = ""; //相交 外切 內(nèi)切 相離

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 = "內(nèi)切";

}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;

}

}

//把測試程序?qū)懺贑ycle的main方法里了

用java代碼 畫圓類

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

class MyCanvas extends Canvas

{

int x,y,r,n;

int x0,y0;

MyCanvas()

{

setSize(圓心位置,圓心位置);

setBackground(Color.red);

}

public void setX(int x)

{

this.x=x;

}

public void setY(int y)

{

this.y=y;

}

public void setR(int r)

{

this.r=r;

}

public void setN(int n)

{

this.n=n;

}

public void paint(Graphics g1)

{

for(int i=0;i=360;i=i+360/n)

{

x0 = (int)(x+r*Math.cos(i));

y0 = (int)(y+r*Math.sin(i));

g1.drawString("*",x0,y0);}

}

}

public class e1 extends Applet implements ActionListener

{

MyCanvas canvas;

TextField inputR,inputX,inputY,inputN;

Label label1,label2,label3;

Button b1,b2;

public void init()

{

canvas = new MyCanvas();

inputR = new TextField(6);

inputX = new TextField(6);

inputY = new TextField(6);

inputN = new TextField(6);

b1 = new Button("確定");

b1.addActionListener(this);

label1 = new Label("輸入位置坐標:");

label2 = new Label("輸入半徑:");

label3 = new Label("輸入要打印的*數(shù):");

add(label1);

add(inputX);

add(inputY);

add(label2);

add(inputR);

add(label3);

add(inputN);

add(b1);

add(canvas);

}

public void actionPerformed(ActionEvent e)

{

int x=0,y=0,n=0,r=0;

try

{

x=Integer.valueOf(inputX.getText()).intValue();

y=Integer.valueOf(inputY.getText()).intValue();

n=Integer.valueOf(inputN.getText()).intValue();

r=Integer.valueOf(inputR.getText()).intValue();

canvas.setX(x);

canvas.setY(y);

canvas.setR(r);

canvas.setN(n);

canvas.repaint();

}

catch(NumberFormatException ee)

{

x = 0;

y = 0;

r = 0;

n = 0;

}

}

}

分享文章:JAVA圓與圓心代碼 java同心圓
文章分享:http://muchs.cn/article6/hgihog.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設計、云服務器Google、網(wǎng)站排名虛擬主機、營銷型網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設