1 import java.applet.*; 2 import java.awt.*; 3 public class Example7_1 extends Applet{ 4 Font f1 = new Font("Helvetica",Font.PLAIN,18); 5 Font f2 = new Font("Helvetica", Font.BOLD,10); 6 Font f3 = new Font("Helvetica",Font.ITALIC,12); 7 Font f4 = new Font("Courier",Font.PLAIN,12); 8 Font f5 = new Font("TimesRoman", Font.BOLD+Font.ITALIC,14); 9 Font f6 = new Font("Dialog",Font.ITALIC,14); 10 public void paint(Graphics g){ 11 setSize(250,200); 12 g.setFont(f1);drawString("18pt plain Helvetica",5,20); 13 g.setFont(f2);drawString("10pt bold Helvetica",5,43); 14 g.setFont(f3);drawString("12pt italic Helvetica",5,58); 15 g.setFont(f4);drawString("12pt plain courier",5,75); 16 g.setFont(f5);drawString("14pt bold & italic times Roman",5,92); 17 g.setFont(f6);drawString("14pt italic dialog",5,111); 18 } 19 }
black | blue | cyan |
darkGray | gray | green |
lightGray | magenta | orange |
pink | red | white |
yellow |
1 import java.applet.*; 2 import java.awt.*; 3 public class Example7_2 extends Applet{ 4 public void paint(Graphics g){ 5 setSize(380,200); 6 for(int i=0;i<=10;i++){ 7 Color myredcolor = new Color(i*25+5,0,0); 8 g.setColor(myredcolor); 9 g.fillRect(i*32+5,2,28,28); 10 } 11 for(int i=0;i<=10;i++){ 12 Color mygreencolor = new Color(0,i*25+5,0); 13 g.setColor(mygreencolor); 14 g.fillRect(i*32+5,32,28,28); 15 } 16 for(int i=0;i<=10;i++){ 17 Color mybluecolor = new Color(0,0,i*25+5); 18 g.setColor(mybluecolor); 19 g.fillRect(i*32+5,62,28,28); 20 } 21 } 22 }
系列文章: