名稱 敘述 Font 設定字型 Color 設定顏色 SystemColor 系統預設顏色
舉例如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import java.awt.*; import java.awt.event.*; public class AWTDemo3 { public static void main(String[] args) { Frame frame = new Frame( "AWTDemo" ); frame.addWindowListener( new AdapterDemo()); frame.setLayout( new FlowLayout()); Label label = new Label( "There is no spoon." ); Font font = new Font(Font.DIALOG_INPUT, Font.ITALIC, 35 ); label.setFont(font); label.setForeground(Color.BLUE); frame.add(label); frame.pack(); frame.setVisible( true ); } } class AdapterDemo extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit( 0 ); } } /* 《程式語言教學誌》的範例程式 檔名:AWTDemo3.java 功能:示範 Java 程式 作者:張凱慶 時間:西元 2012 年 3 月 */ |
此例建立一個 Label 物件,然後建立 Font 設定所屬字型,並利用 Color 的 BLUE 屬性將文字顏色設定成藍色
6 7 8 9 10 | Label label = new Label( "There is no spoon." ); Font font = new Font(Font.DIALOG_INPUT, Font.ITALIC, 35 ); label.setFont(font); label.setForeground(Color.BLUE); frame.add(label); |
編譯後執行,結果如下

中英文術語對照 | |
---|---|
類別 | class |
建構子 | constructor |
方法 | method |
您可以繼續參考
java.awt
- CheckboxGroup
- Component
- Button
- Canvas
- Checkbox
- Choice
- Container
- Panel
- ScrollPane
- Window
- Dialog
- FileDialog
- Frame
- Label
- List
- Scrollbar
- TextComponent
- TextArea
- TextField
- MenuComponent
- MenuBar
- MenuItem
- CheckboxMenuItem
- Menu
- PopupMenu
- MenuShortcut
相關目錄
Java API 分類導覽
Java 教材
首頁
參考資料
http://docs.oracle.com/javase/6/docs/api/java/awt/Font.html
http://docs.oracle.com/javase/6/docs/api/java/awt/Color.html
http://docs.oracle.com/javase/6/docs/api/java/awt/SystemColor.html
沒有留言:
張貼留言