java绘制圆形代码 java画图代码圆形

用JAVA编写圆代码如下:
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); ///此方法将画一个直径100的圆.红色. }}}
急求Java代码 , 定义一个Circle(圆类型)public class Exam
{
public static void main(String[] args)
{
Circle c=new Circle(3,4,5);
System.out.printf("圆心java绘制圆形代码:(%f,%f)java绘制圆形代码,半径java绘制圆形代码:%fjava绘制圆形代码,面积:%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编程:定义一个圆circle类,包含如下内容代码如下:
import java.util.Scanner;
class Circle {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double getArea() {
return Math.PI * radius * radius;
}
public double getPerimeter() {
return 2 * Math.PI * radius;
}
}
public class App {
public static void main(String[] argv) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入圆半径:");
【java绘制圆形代码 java画图代码圆形】double r = scanner.nextDouble();
Circle c = new Circle(r);
System.out.println("面积:" + c.getArea() + ",周长:" + c.getPerimeter());
}
}
运行结果:
JAVA画圆import java.awt.Frame;
import java.awt.Graphics;
public class S extends Frame{
private int x;
private int y;
private boolean drawOval;//为true时绘制
//测试入口函数
public static void main(String []args)
{
new S().print();
}
//构造函数,初始化x、y坐标,设置drawOval变量为false , 设置窗体大小
public S()
{
x = 200;
y = 200;
drawOval = false;
this.setSize(400,400);
this.setVisible(true);
}
public void print(){
//在调用S类实例的print方法时,画一个以属性X,Y为起点的宽高为10的圆.
drawOval = true;//设置drawOval变量为true
repaint();//调用刷新画面方法
}
public void paint(Graphics g)
{
//为true时绘制
if(drawOval)g.fillOval(x,y,10,10);
}
}
求Java三角形圆形代码过程!急急急?。。?/h2>public class Test {
public static void main(String[] args) {
//三角形
Triangle t = new Triangle(3.0,4.0,5.0);
t.GetArea();
//圆形
Circlec = new Circle(5.0);
c.getArea();
}
}
class Triangle {
double x, y, z, p, s;
public Triangle(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public void GetArea() {
if (x + y = z || x + z = y || y + z = x)
System.out.println("不能构成三角形");
else {
p = (x + y + z) / 2;
s = (double) Math.sqrt(p * (p - x) * (p - y) * (p - z));
System.out.println("三角形面积为:"+s);

推荐阅读