java画圆形的代码 java绘制圆形
JAVA画圆
import java.awt.Frame;
创新互联建站自2013年创立以来,是专业互联网技术服务公司,拥有项目成都网站设计、网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元霍山做网站,已为上家服务,为霍山各地企业和个人服务,联系电话:18982081108
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三角形圆形代码过程!急急急!!!
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编写圆
代码如下:
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画圆形的代码 java绘制圆形
URL分享:http://ybzwz.com/article/docjcic.html