/** 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.*;
//import java.awt.Graphics;

public class MyApplet6 extends java.applet.Applet 
      {public void paint(Graphics g)
     {Font f = new Font("TimesRoman", Font.PLAIN, 18);
      Font  fb = new Font("TimesRoman", Font.BOLD, 18);
       Font  fi = new Font("TimesRoman", Font.ITALIC, 18);
       Font  fbi = new Font("TimesRoman", Font.BOLD + Font.ITALIC, 18);
        
      FontMetrics fm = getFontMetrics(f);         // The different font metrics.
	int xstartf = 
	    (size().width - fm.stringWidth("This is a plain font"))/2;
	
	
	
	FontMetrics fbm = getFontMetrics(fb);
	int xstartfb = 
	    (size().width - fbm.stringWidth("This is a bold font"))/2;
		
	FontMetrics fim = getFontMetrics(fi);
	int xstartfi = 
	    (size().width - fim.stringWidth("This is an italic font"))/2;
		
	FontMetrics fbim = getFontMetrics(fbi);       
	int xstartfbi = 
	    (size().width - fbim.stringWidth("This is a bold italic font"))/2;
	   
	int fontfht = fm.getHeight();                          // Get font heights.
	int fontfbht = fbm.getHeight();
	int fontfiht = fim.getHeight();
	int fontfbiht = fbim.getHeight();           
	         
							    // Compute spacing between lines.
	int yspacing = (size().height - (fontfht + fontfbht +fontfiht + fontfbiht))/5; 
					       
	
	             // Align text vertically.
	int ystartf = yspacing + fm.getAscent();
	int ystartfb = ystartf + fm.getDescent() + yspacing + fbm.getAscent();
	int ystartfi = ystartfb + fbm.getDescent() + yspacing + fim.getAscent();
	int ystartfbi = ystartfi + fim.getDescent() + yspacing + fbim.getAscent();  
    

       {g.setFont(f);
       g.setColor(Color.green);
       g.drawString("This is a plain font", xstartf, ystartf);
       g.setColor(Color.cyan);
       g.setFont(fb);
       g.drawString("This is a bold font", xstartfb, ystartfb);
       g.setColor(Color.blue);
       g.setFont(fi);
       g.drawString("This is an italic font", xstartfi, ystartfi);
       g.setColor(Color.orange);
       g.setFont(fbi);
       g.drawString("This is a bold italic font", xstartfbi, ystartfbi);         
             

	 
        
        }
    }
}