import java.awt.Frame;

創(chuàng)新互聯(lián)建站自2013年創(chuàng)立以來,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元霍山做網(wǎng)站,已為上家服務(wù),為霍山各地企業(yè)和個人服務(wù),聯(lián)系電話:18982081108
import java.awt.Graphics;
public class S extends Frame{
private int x;
private int y;
private boolean drawOval;//為true時繪制
//測試入口函數(shù)
public static void main(String []args)
{
new S().print();
}
//構(gòu)造函數(shù),初始化x、y坐標(biāo),設(shè)置drawOval變量為false,設(shè)置窗體大小
public S()
{
x = 200;
y = 200;
drawOval = false;
this.setSize(400,400);
this.setVisible(true);
}
public void print(){
//在調(diào)用S類實(shí)例的print方法時,畫一個以屬性X,Y為起點(diǎn)的寬高為10的圓.
drawOval = true; //設(shè)置drawOval變量為true
repaint(); //調(diào)用刷新畫面方法
}
public void paint(Graphics g)
{
//為true時繪制
if(drawOval)g.fillOval(x,y,10,10);
}
}
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("不能構(gòu)成三角形");
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);
}
}
我建的是類部類,你移出去一樣的。希望能幫到你!
代碼如下:
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繪制圓形
網(wǎng)頁URL:http://www.yijiale78.com/article2/docjcic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、營銷型網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、移動網(wǎng)站建設(shè)、定制開發(fā)、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)