
正文
java重置圆形的代码 java怎么重置
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
急求JAVA代码,定义一个Circle类(圆形类),有设置圆半径的方法、求圆的面积的方法、求圆的周长的方法。
//圆心坐标在此题中无用,是否是需求有问题。
public class Circle {
double x;
double y;
double r;
double area;
double length;
public static void main(String[] args) {
Circle c = new Circle();
c.setR(2);
c.getArea();
c.getLength();
c.setXY(0, 0);
}
void setXY(double x, double y) {
this.x = x;
this.y = y;
}
void setR(double r) {
this.r = r;
}
void getArea() {
area = java.lang.Math.PI * r * r;
}
void getLength() {
length = 2 * java.lang.Math.PI * r;
}
}
相关问答
Q1: 在Java中如何用程序画一个圆
使用java画圆要用到绘图类Graphics,下面是实例代码和运行效果:
package com.dikea.demo01;
import java.awt.*;
import javax.swing.*;
// java绘图原理
public class demo_01 extends JFrame {
MyPanel mp = null;
public static void main(String[] args) {
// TODO 自动生成的方法存根
demo_01 demo01 = new demo_01();
}
public demo_01(){
mp = new MyPanel();
this.add(mp);
this.setSize(400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
// 定义一个MyPanel面板,用于绘图区域
class MyPanel extends JPanel{
//覆盖JPanel
// Graphics 是绘图的重要类,可以理解成一支画笔
public void paint(Graphics g){
// 1. 调用父类函数完成初始化任务
// 这句话不可以少
super.paint(g);
// 先画出一个圆圈
g.drawOval(100, 100, 30, 30);
}
}
代码复制进ide编程工具,运行效果如下:
Q2: 急求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;
}
Q3: 求Java三角形圆形代码过程!急急急!!!
public class Test {
public static void main(String[] args) {
//三角形
Triangle t = new Triangle(3.0,4.0,5.0);
t.GetArea();
//圆形
Circle c = 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);
}
}
}
class Circle {
double r ;
public Circle(double r){
this.r = r;
}
public void getArea() {
double S = Math.PI * r * r;
System.out.print("圆形面积为:" + S);
}
}
java重置圆形的代码我建的是类部类,java重置圆形的代码你移出去一样的。希望能帮到java重置圆形的代码你java重置圆形的代码!
Q4: java 定义一个圆类Circle,就解
public class Circle {
//圆java重置圆形的代码的半径
private double radius;
//求圆java重置圆形的代码的面积
public double findArea() {
return Math.PI*radius*radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
}
测试类自己去写。
Q5: JAVA实现一个圆形的移动,画出来的圆形移动,我的圆它不动呀
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JFrame;
public class JoinDemo extends JFrame {
public static void main(String[] args) {
new JoinDemo();
}
private int x = 100, y = 100, r = 100;
public JoinDemo() {
this.setTitle("小图形");
this.setSize(800, 600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
new UpdateThread().start();
}
public void paint(Graphics g) {
Image image = createImage(getWidth(), getHeight());
Graphics gg = image.getGraphics();
bufferedPaint(gg);
gg.dispose();
g.drawImage(image, 0, 0, null);
}
private void bufferedPaint(Graphics gg) {
gg.fillOval(x, y, r, r);
}
class UpdateThread extends Thread {
public void run() {
for (int j = 0; j = 240; j++) {
y++;
repaint();
sleep(10);
}
}
private void sleep(int millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
说明:
第一:存为JoinDemo.java
第二:加入了一个缓冲,以免画面闪烁。
java重置圆形的代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java怎么重置、java重置圆形的代码的信息别忘了在本站进行查找喔。






