修飾子
public static final Color green
public static final Color GREEN
舉例如下
import java.awt.*; import java.awt.event.*; public class ColorDemo1 { public static void main(String[] args) { Frame frame = new Frame("AWTDemo"); frame.addWindowListener(new AdapterDemo()); frame.setLayout(new GridLayout(13, 1)); Label word1 = new Label("There is no spoon."); word1.setBackground(Color.BLACK); Label word2 = new Label("There is no spoon."); word2.setBackground(Color.BLUE); Label word3 = new Label("There is no spoon."); word3.setBackground(Color.CYAN); Label word4 = new Label("There is no spoon."); word4.setBackground(Color.DARK_GRAY); Label word5 = new Label("There is no spoon."); word5.setBackground(Color.GRAY); Label word6 = new Label("There is no spoon."); word6.setBackground(Color.GREEN); Label word7 = new Label("There is no spoon."); word7.setBackground(Color.LIGHT_GRAY); Label word8 = new Label("There is no spoon."); word8.setBackground(Color.MAGENTA); Label word9 = new Label("There is no spoon."); word9.setBackground(Color.ORANGE); Label word10 = new Label("There is no spoon."); word10.setBackground(Color.PINK); Label word11 = new Label("There is no spoon."); word11.setBackground(Color.RED); Label word12 = new Label("There is no spoon."); word12.setBackground(Color.WHITE); Label word13 = new Label("There is no spoon."); word13.setBackground(Color.YELLOW); frame.add(word1); frame.add(word2); frame.add(word3); frame.add(word4); frame.add(word5); frame.add(word6); frame.add(word7); frame.add(word8); frame.add(word9); frame.add(word10); frame.add(word11); frame.add(word12); frame.add(word13); frame.pack(); frame.setVisible(true); } } class AdapterDemo extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } /* 《程式語言教學誌》的範例程式 http://pydoing.blogspot.com/ 檔名:ColorDemo1.java 功能:示範 Java 程式 作者:張凱慶 時間:西元 2012 年 3 月 */
此例建立 13 個 Label 物件,依次將背景顏色設定為黑色 Color.BLACK 、藍色 Color.BLUE 、青色 Color.CYAN 、深灰色Color.DARK_GRAY 、灰色 Color.GRAY 、綠色 Color.GREEN 、淺灰色 Color.LIGHT_GRAY 、洋紅色 Color.MAGENTA 、橘色 Color.ORANGE 、粉紅色 Color.PINK 、紅色 Color.RED 、白色 Color.WHITE 及黃色 Color.YELLOW
Label word1 = new Label("There is no spoon."); word1.setBackground(Color.BLACK); Label word2 = new Label("There is no spoon."); word2.setBackground(Color.BLUE); Label word3 = new Label("There is no spoon."); word3.setBackground(Color.CYAN); Label word4 = new Label("There is no spoon."); word4.setBackground(Color.DARK_GRAY); Label word5 = new Label("There is no spoon."); word5.setBackground(Color.GRAY); Label word6 = new Label("There is no spoon."); word6.setBackground(Color.GREEN); Label word7 = new Label("There is no spoon."); word7.setBackground(Color.LIGHT_GRAY); Label word8 = new Label("There is no spoon."); word8.setBackground(Color.MAGENTA); Label word9 = new Label("There is no spoon."); word9.setBackground(Color.ORANGE); Label word10 = new Label("There is no spoon."); word10.setBackground(Color.PINK); Label word11 = new Label("There is no spoon."); word11.setBackground(Color.RED); Label word12 = new Label("There is no spoon."); word12.setBackground(Color.WHITE); Label word13 = new Label("There is no spoon."); word13.setBackground(Color.YELLOW);
編譯後執行,結果如下
中英文術語對照 | |
---|---|
類別 | class |
屬性 | field |
參數 | parameter |
您可以繼續參考
字型與顏色
相關目錄
Java API 分類導覽
Java 教材
首頁
參考資料
http://docs.oracle.com/javase/6/docs/api/java/awt/Color.html
沒有留言:
張貼留言