import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.TextAttribute;
import java.text.AttributedString;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class IteratorUnderStrike extends JPanel{
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
String s = "\"www.java2java.com\" is great.";
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Font plainFont = new Font("Times New Roman", Font.PLAIN, 24);
AttributedString as = new AttributedString(s);
as.addAttribute(TextAttribute.FONT, plainFont);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1,
15);
as.addAttribute(TextAttribute.STRIKETHROUGH,
TextAttribute.STRIKETHROUGH_ON, 18, 25);
g2.drawString(as.getIterator(), 24, 70);
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.getContentPane().add(new IteratorUnderStrike());
f.setSize(850, 250);
f.show();
}
}
|