/** Assignment:  Modify this file (previously ManyFonts
 ** on p. 202 of the text) by changing it to center each 
 ** of the different fonts horizontally, and to give each        
 ** a different color. Make sure to check out SimpleApplet3 
 ** first, which shows how to do these things.  Also, edit 
 ** MyApplet6.html in the  project directory, to run the
 ** MyApplet6.class file you create, and to look nice.   **/                                                               

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.FontMetrics;

public class MyApplet6 extends java.applet.Applet 
  {public void init()
    {setBackground(new Color (120,10,100));}
  public void paint(Graphics g) 
      {Font f = new Font("TimesRoman", Font.PLAIN, 23);
       Font fb = new Font("TimesRoman", Font.BOLD, 23);
       Font fi = new Font("TimesRoman", Font.ITALIC, 23);
       Font fbi = new Font("TimesRoman", Font.BOLD + Font.ITALIC, 23);
       
       FontMetrics font1m = getFontMetrics(f);
       FontMetrics font2m = getFontMetrics(fb);
       FontMetrics font3m = getFontMetrics(fi);
       FontMetrics font4m = getFontMetrics(fbi);
       
       int xstart1 = (size().width - font1m.stringWidth("This is a plain font"))/2;
       int xstart2 = (size().width - font2m.stringWidth("This is a bold font"))/2;
       int xstart3 = (size().width - font3m.stringWidth("This is a italic font"))/2;
       int xstart4 = (size().width - font4m.stringWidth("This is a bold italic font"))/2;
       
       g.setFont(f);
       g.setColor(new Color (0,178,0));
       g.drawString("This is a plain font", xstart1,25);
       g.setFont(fb);
       g.setColor(Color.white);
       g.drawString("This is a bold font", xstart2, 50);
       g.setColor(new Color (101,203,254));
       g.setFont(fi);
       g.drawString("This is an italic font", xstart3, 75);
       g.setColor(new Color (255,159,140));
       g.setFont(fbi);
       g.drawString("This is a bold italic font", xstart4, 100);
         
       {setBackground(new Color (120,10,100));}
       
       }
    }