skip to main |
skip to sidebar
import java.applet.*;
import java.awt.*;
/*
<applet code="cstr" width=200 height=200>
</applet>
*/
public class cstr extends Applet
{
Font f=new Font("courier",Font.BOLD|Font.ITALIC,36);
String msg="WELCOME TO JAVA";
public void paint(Graphics g)
{
Dimension d=this.getSize();
g.setFont(f);
drawCenteredString(msg,d.width,d.height,g);
}
public void drawCenteredString(String s,int w,int h,Graphics g)
{
FontMetrics fm=g.getFontMetrics();
int x=(w-fm.stringWidth(s))/2;
int y=(fm.getAscent()+(h-(fm.getAscent()+fm.getDescent()))/2);
g.drawString(s,x,y);
}
}
OUTPUT
0 comments:
Post a Comment