Created
February 28, 2014 08:44
-
-
Save fcflyinsky/9267559 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.Line2D; | |
import java.awt.geom.Rectangle2D; | |
import javax.swing.JFrame; | |
public class Ex13_303 extends JFrame { | |
public Ex13_303() { | |
setTitle("設定線條"); | |
// 設定視窗大小 | |
setSize(300, 300); | |
// 設定視窗大小不可更改 | |
setResizable(false); | |
// 顯示視窗物件 | |
this.setVisible(true); | |
} | |
public static void main(String[] args) { | |
new Ex13_303(); | |
} | |
public void paint(Graphics g) { | |
// 建立Graphics2D子類別實體 | |
Graphics2D G2D = (Graphics2D) g; | |
// 設定線條顏色 | |
G2D.setColor(Color.red); | |
// 設定漸線條格式 | |
// new BasicStroke(寬度, 兩端點樣式, 連接線段樣式); | |
BasicStroke sk1 = new BasicStroke(5, BasicStroke.CAP_BUTT, | |
BasicStroke.JOIN_BEVEL); | |
// 設定繪圖樣式 | |
G2D.setStroke(sk1); | |
// 直線 | |
// new Line2D.Double(起始x,起始y,結束x,結束y); | |
Line2D ld = new Line2D.Double(50, 70, 200, 70); | |
G2D.draw(ld); | |
// 設定相接的地方為圓角 | |
BasicStroke sk2 = new BasicStroke(10, BasicStroke.CAP_ROUND, | |
BasicStroke.JOIN_ROUND); | |
G2D.setStroke(sk2); | |
// 矩形 | |
// new Line2D.Double(基準x,基準y,長,寬); | |
Rectangle2D rt = new Rectangle2D.Double(50, 150, 100, 100); | |
G2D.draw(rt); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment