/** 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 font1 = new Font("TimesRoman", Font.PLAIN, 18);
       Font font2 = new Font("TimesRoman", Font.BOLD, 18);
       Font font3 = new Font("TimesRoman", Font.ITALIC, 18);
       Font font4 = new Font("TimesRoman", Font.BOLD + Font.ITALIC, 18);
       
        FontMetrics font1m = getFontMetrics(font1);      
        FontMetrics font2m = getFontMetrics(font2);
        FontMetrics font3m = getFontMetrics(font3);
        FontMetrics font4m = getFontMetrics(font4);     

        String text1 = "sima's";     
        String text2 = "centered";
        String text3 = "JAVA";
        String text4 = "text.";
        
        int font1ht = font1m.getDescent() + font1m.getAscent();                          // Get font heights.
        int font2ht = font2m.getDescent() + font2m.getAscent();
        int font3ht = font3m.getDescent() + font3m.getAscent();
        int font4ht = font4m.getDescent() + font4m.getAscent();       
	
	 public void init()  
       {setBackground(Color.white);} 
       
    public void paint(Graphics g) 
      {     
        int xstart1 = (size().width - font1m.stringWidth(text1))/2;              
        int xstart2 = (size().width - font2m.stringWidth(text2))/2;
        int xstart3 = (size().width - font3m.stringWidth(text3))/2; 
        int xstart4 = (size().width - font4m.stringWidth(text4))/2;
        int yspacing = (size().height - (font1ht + font2ht +font3ht + font4ht))/5;
        int ystart1 = (yspacing + (font1ht/2));                                         
        int ystart2 = ((yspacing*2) + font1ht + (font2ht/2));
        int ystart3 = ((yspacing*3) + font1ht + font2ht + (font3ht/2));
        int ystart4 = ((yspacing*4) + font1ht + font2ht + font3ht + (font4ht/2));
	
       
        g.setFont(font1);                               
        g.setColor(Color.blue);
        g.drawString(text1, xstart1, ystart1);
          
        g.setFont(font2);
        g.setColor(Color.red);
        g.drawString(text2, xstart2, ystart2);
       
        g.setFont(font3);
        g.setColor(Color.magenta);
        g.drawString(text3, xstart3, ystart3);
       
        g.setFont(font4);
        g.setColor(Color.green);
        g.drawString(text4, xstart4, ystart4);
       }
    }
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       