Belajar Menggunakan FontMetrics

Bookmark and Share

Menggunakan FontMetrics

import java.awt.Font;
import java.awt.Graphics;
import java.awt.FontMetrics;
import java.applet.*;
public class textCenter extends Applet{

public void paint (Graphics g){
Font f=new Font("TimesRoman", Font.BOLD, 36);
FontMetrics fm = getFontMetrics(f);
g.setFont(f);
String S="Teks ini tampil di tengah";
int xpos=(this.size().width-fm.stringWidth(S))/2;
int ypos=(this.size().height)/2;
g.drawString(S, xpos, ypos);
}


}

{ 0 komentar... Views All / Send Comment! }

Posting Komentar