/** 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.*;

public class MyApplet6 extends java.applet.Applet 
 
      {Font f = new Font("TimesRoman", Font.PLAIN, 25);
      Font  fb = new Font("TimesRoman", Font.BOLD, 25);
       Font  fi = new Font("TimesRoman", Font.ITALIC, 25);
       Font  fbi = new Font("TimesRoman", Font.BOLD + Font.ITALIC, 25);
       
       public void paint(Graphics g)   
	{FontMetrics fm = getFontMetrics(f);         // The different font metrics.
        int xstartf = 
            (size().width - fm.stringWidth("Pyar Kiya Tho Darna Kya..."))/2;
        
        
        
        FontMetrics fbm = getFontMetrics(fb);
        int xstartfb = 
            (size().width - fbm.stringWidth("Dil Tho Pagal Hai..."))/2;
                
        FontMetrics fim = getFontMetrics(fi);
        int xstartfi = 
            (size().width - fim.stringWidth("Hum Aapke Hain Koun..."))/2;
                
        FontMetrics fbim = getFontMetrics(fbi);       
        int xstartfbi = 
            (size().width - fbim.stringWidth("Maine Pyar Kiya..."))/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("Pyar Kiya Tho Darna Kya...", xstartf, ystartf);
       g.setColor(Color.cyan);
       g.setFont(fb);
       g.drawString("Dil Tho Pagal Hai...", xstartfb, ystartfb);
       g.setColor(Color.blue);
       g.setFont(fi);
       g.drawString("Hum Aapke Hain Koun...", xstartfi, ystartfi);
       g.setColor(Color.orange);
       g.setFont(fbi);
       g.drawString("Maine Pyar Kiya...", xstartfbi, ystartfbi);         
             

         
        
        }
    }
}