import java.applet.Applet;

我們提供的服務(wù)有:成都網(wǎng)站制作、成都做網(wǎng)站、微信公眾號(hào)開(kāi)發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、瓦房店ssl等。為千余家企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢(xún)和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的瓦房店網(wǎng)站制作公司
import java.awt.Graphics;
public class draw extends Applet{
public void paint(Graphics g){
g.drawOval(100,200,50,50);
或者將pain里面改為g.drawRoundRect(120,200,30,30,30,30);
也就頃談是說(shuō)drawOval和雀昌碰drawRoundRect都可以畫(huà)圓迅笑.
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("野枝態(tài)*",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;
}
}
}
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author szmneo
*/
public class DrawCircle {
static JFrame frame = new JFrame();
static DrawPanel p1 = new DrawPanel();
static JLabel l1 = new JLabel("直徑:");
static JLabel l2 = new JLabel("弊肆周長(zhǎng):");
static JLabel l3 = new JLabel("面積:");
static JTextField tx = new JTextField("輸入半徑"瞎絕,10);
public static void main(String[] args){
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
JPanel p4 = new JPanel();
JButton b1 = new JButton("OK");
JButton b2 = new JButton("Clear");
p2.add(tx);
p2.add(b1);
p2.add(b2);
p3.setLayout(new GridLayout(3,1));
p3.add(l1);
p3.add(l2);
p3.add(l3);
p4.add(p2);
p4.add(p3);
frame.setLayout(new BorderLayout());
frame.add(p1,BorderLayout.CENTER);
frame.add(p4,BorderLayout.SOUTH);
frame.setTitle("Draw Circles");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,400);
frame.setVisible(true);
b1.addActionListener(new ActionListener() {//添加磨卜姿繪制事件
public void actionPerformed(ActionEvent e) {
DrawAction();
}
});
b2.addActionListener(new ActionListener() {//添加清除事件
public void actionPerformed(ActionEvent e) {
ClearAction();
}
});
}
static void DrawAction(){
float r = 0;
try {
r = Float.parseFloat(tx.getText());
} catch (NumberFormatException numberFormatException) {
tx.setText("請(qǐng)輸入數(shù)字(0-400)");
}
l1.setText("直徑:" + Float.toString(2 * r));
l2.setText("周長(zhǎng):" + Float.toString((float) (2 * r * Math.PI)));
l3.setText("面積:"+ Float.toString((float) (Math.PI * r * r)));
p1.setR(r);
p1.repaint();
frame.repaint();
frame.setVisible(true);
}
static void ClearAction(){
p1.Clear();
p1.repaint();
frame.repaint();
frame.setVisible(true);
}
static class DrawPanel extends JPanel{
int x,y;
float r=0f;
ArrayList CircleData = new ArrayList();
void setR(float r){
this.r=r;
x = (int)(Math.random()*getWidth()-2*r)+1;
if(x0)x=0;
y = (int)(Math.random()*getHeight()-2*r)+1;
if(y0)y=0;
Circle circle = new Circle();
circle.setR(r);
circle.setX(x);
circle.setY(y);
CircleData.add(circle);//添加一個(gè)圓
}
void Clear(){
CircleData = new ArrayList();//清空列表
repaint();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
for(int i=0;iCircleData.size();i++){//畫(huà)每個(gè)圓
int a =((Circle)CircleData.get(i)).getX();
int b =((Circle)CircleData.get(i)).getY();
int d =(int)(2*((Circle)CircleData.get(i)).getR());
g.drawArc(a, b, d, d, 0, 360);
}
}
}
}
class Circle {//定義每個(gè)圓的信息
int x,y;
float r=0f;
void setR(float r){
this.r=r;
}
void setX(int x){
this.x=x;
}
void setY(int y){
this.y=y;
}
float getR(){
return r;
}
int getX(){
return x;
}
int getY(){
return y;
}
}
新聞標(biāo)題:隨機(jī)畫(huà)圓java代碼 python隨機(jī)畫(huà)圓
URL網(wǎng)址:http://chinadenli.net/article46/dsphchg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、用戶(hù)體驗(yàn)、App設(shè)計(jì)、全網(wǎng)營(yíng)銷(xiāo)推廣、企業(yè)網(wǎng)站制作、網(wǎng)站營(yíng)銷(xiāo)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)