欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java代碼怎么畫圓 javagui畫圓

用JAVA編寫圓

代碼如下:

創(chuàng)新互聯(lián)公司專注于仁壽企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,電子商務(wù)商城網(wǎng)站建設(shè)。仁壽網(wǎng)站建設(shè)公司,為仁壽等地區(qū)提供建站服務(wù)。全流程按需制作網(wǎng)站,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)

import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class TestSw extends JFrame { public static void main(String[] args) { new TestSw(); } public TestSw(){ super("Test"); this.setSize(new Dimension(400,300)); this.setContentPane(new Mypane()); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } class Mypane extends JPanel{ public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); g.setXORMode(Color.white); g.drawArc(20, 20, 100, 100, 0, 360); ///此方法將畫一個(gè)直徑100的圓.紅色. } } }

用java畫一個(gè)圓

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

class MyCanvas extends Canvas

{

int x,y,r,n;

int x0,y0;

MyCanvas()

{

setSize(100,100);

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("輸入位置坐標(biāo):");

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;

}

}

}

public void draw(Graphics2D g) {

g.setColor(color);//設(shè)置顏色

g.setStroke(stroke);//寬度

int x, y, w, h;

if (startX endX) {//以下的startx 、endx都是由鼠標(biāo)拖 動(dòng)事件得到

x = endX;

w = startX - endX;

} else {

x = startX;

w = endX - startX;

}

if (startY endY) {

y = endY;

h = startY - endY;

} else {

y = startY;

h = endY - startY;

}

g.drawOval(x, y, w, h);

}

請(qǐng)寫出用java代碼畫一個(gè)圓

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

drawOval(int

x,int

y,int

w,int

h);

這是是畫橢圓形的函數(shù),但是它也可以畫圓形。

比如

drawOval(100,100,50,50);

就在坐標(biāo)50,50畫一個(gè)直徑100的圓,只要把,最后的2個(gè)參數(shù)設(shè)成一樣就是一個(gè)圓。要畫直徑200的話,就把最后2個(gè)參數(shù)設(shè)成200,200

一切OK了

java代碼畫出一個(gè)圓

你先想這道題的思路吧。

首先打印出圓形的話就是在一個(gè)60-60這種正方形里面話個(gè)圓,你先要知道要畫的點(diǎn)的位置對(duì)吧。算出所有的點(diǎn)打印出來(lái)。就是這個(gè)思路。然后是怎么算的問(wèn)題了

public?class?SSS?{

public?static?void?main(String[]?args)?{

//半徑

int?r?=?30;

for?(int?y?=?0;?y?=?2?*?r;?y?+=?2)?{

long?x?=?Math.round(r?-?Math.sqrt(2?*?r?*?y?-?y?*?y));

long?longLength?=?2?*?(r?-?x);

for?(int?i?=?0;?i?=?x;?i++)?{

System.out.print('?');

}

System.out.print('*');

for?(int?j?=?0;?j?=?longLength;?j++)?{

System.out.print('?');

}

System.out.println('*');

}

}

}

新聞名稱:java代碼怎么畫圓 javagui畫圓
網(wǎng)頁(yè)路徑:http://chinadenli.net/article42/dojdchc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站動(dòng)態(tài)網(wǎng)站電子商務(wù)ChatGPT云服務(wù)器網(wǎng)站維護(hù)

廣告

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

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