Created
February 24, 2014 12:59
-
-
Save fcflyinsky/9187945 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.geom.Arc2D; | |
import java.awt.geom.Line2D; | |
import java.awt.geom.Rectangle2D; | |
import javax.swing.JFrame; | |
public class Ex13_301 extends JFrame { | |
public Ex13_301() { | |
setTitle("Graphics2D繪圖"); | |
// 設定視窗大小 | |
setSize(300, 300); | |
// 設定視窗大小不可更改 | |
setResizable(false); | |
// 顯示視窗物件 | |
this.setVisible(true); | |
} | |
public static void main(String[] args) { | |
new Ex13_301(); | |
} | |
public void paint(Graphics g) { | |
// 建立Graphics2D子類別實體 | |
Graphics2D G2D = (Graphics2D) g; | |
// 設定繪圖顏色 | |
G2D.setColor(Color.blue); | |
// 直線 | |
// Line2D.Double(起始x,起始y,結束x,結束y); | |
Line2D line = new Line2D.Double(50, 50, 150, 50); | |
// 繪圖 | |
// 繪圖物件.draw(物件); | |
G2D.draw(line); | |
// 中空矩形 | |
// new Rectangle2D.Double(基準點x, 基準點y, 長, 寬); | |
Rectangle2D rectangle1 = new Rectangle2D.Double(50, 100, 50, 50); | |
G2D.draw(rectangle1); | |
// 填滿矩形 | |
Rectangle2D rectangle2 = new Rectangle2D.Double(150, 100, 50, 50); | |
G2D.fill(rectangle2); | |
// 圓弧 | |
// new Arc2D.Double(基準點x, 基準點y, x軸直徑長, y軸直徑長, 起始角度, 長度角度, Arc2D.OPEN); | |
Arc2D arc1 = new Arc2D.Double(50, 200, 50, 50, 0, 90, Arc2D.OPEN); | |
G2D.draw(arc1); | |
// 填滿扇形 | |
Arc2D arc2 = new Arc2D.Double(100, 200, 50, 50, 0, 90, Arc2D.PIE); | |
G2D.fill(arc2); | |
// 中空扇形 | |
Arc2D arc3 = new Arc2D.Double(150, 200, 50, 50, 0, 90, Arc2D.CHORD); | |
G2D.draw(arc3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment