The variable map is which allows you to assign design attributes of the object type source AttributedString. Through this variable may change any aspect of the font . TextAttribute example shown the code as follows:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.Shape;
import java.awt.font.*;
import java.text.*;
import javax.swing.*;
public class DrawTextAttributeExample extends Applet {
public static void main(String[] args) {
Frame DrawTextAttribute = new Frame("Draw TextAttribute Example");
DrawTextAttribute .setSize(350, 250);
Applet DrawTextAttributeExample = new DrawTextAttributeExample();
DrawTextAttribute .add(DrawTextAttributeExample);
DrawTextAttribute .setVisible(true);
DrawTextAttribute .addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void paint(Graphics g) {
g.setColor(Color.blue);
g.setFont(new Font("Arial",Font.BOLD,14));
g.drawString("TextAttribute in Java Example", 50, 40);
g.setFont(new Font("Arial",Font.BOLD,10));
g.drawString("http://ecomputernotes.com", 200, 205);
Graphics2D G2D = (Graphics2D)g;
G2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
G2D.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
G2D.setColor(Color.blue);
String str = "Dinesh Thakur";
AttributedString AttributedStr = new AttributedString (str);
Font font = new Font("Arial", Font.ITALIC, 15);
AttributedStr.addAttribute(TextAttribute.FONT,font,0,str.length()-2);
Image image = (new ImageIcon("DineshThakur.jpg")).getImage();
ImageGraphicAttribute ImageGA = new ImageGraphicAttribute (image,(int)CENTER_ALIGNMENT);
AttributedStr.addAttribute(TextAttribute.CHAR_REPLACEMENT,ImageGA,1,2);
AttributedStr.addAttribute(TextAttribute.CHAR_REPLACEMENT,ImageGA,8,9);
font = new Font("Times", Font.ITALIC, 24);
AttributedStr.addAttribute(TextAttribute.FONT,font,3,9);
AttributedCharacterIterator AttributedCI = AttributedStr.getIterator();
FontRenderContext FontRC = G2D.getFontRenderContext();
TextLayout TextLay = new TextLayout(AttributedCI,FontRC);
TextLay.draw(G2D, 80, 70);
}
}