Created
February 25, 2014 10:38
-
-
Save fcflyinsky/9206626 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.Rectangle2D; | |
import javax.swing.JFrame; | |
public class Ex13_302 extends JFrame { | |
public Ex13_302() { | |
setTitle("漸層色"); | |
// 設定視窗大小 | |
setSize(300, 300); | |
// 設定視窗大小不可更改 | |
setResizable(false); | |
// 顯示視窗物件 | |
this.setVisible(true); | |
} | |
public static void main(String[] args) { | |
new Ex13_302(); | |
} | |
public void paint(Graphics g) { | |
// 建立Graphics2D子類別實體 | |
Graphics2D G2D = (Graphics2D) g; | |
// 設定漸層色物件 | |
// new GradientPaint(起始x, 起始y, 起始顏色, 終止x, 終止y, 中止顏色); | |
GradientPaint gr1 = new GradientPaint(50, 50, Color.red, 150, 150, | |
Color.white); | |
// 設定繪圖樣式 | |
G2D.setPaint(gr1); | |
// 填滿矩形 | |
Rectangle2D rd1 = new Rectangle2D.Double(50, 50, 100, 100); | |
G2D.fill(rd1); | |
GradientPaint gr2 = new GradientPaint(180, 50, Color.blue, 280, 150, | |
Color.white); | |
G2D.setPaint(gr2); | |
Rectangle2D rd2 = new Rectangle2D.Double(180, 50, 100, 100); | |
G2D.fill(rd2); | |
GradientPaint gr3 = new GradientPaint(50, 180, Color.orange, 150, 280, | |
Color.white); | |
G2D.setPaint(gr3); | |
Rectangle2D rd3 = new Rectangle2D.Double(50, 180, 100, 100); | |
G2D.fill(rd3); | |
GradientPaint gr4 = new GradientPaint(180, 180, Color.green, 280, 280, | |
Color.white); | |
G2D.setPaint(gr4); | |
Rectangle2D rd4 = new Rectangle2D.Double(180, 180, 100, 100); | |
G2D.fill(rd4); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment