Name : Shreyal Mandot
Title : Assignment 8a1. Create an applet to display a message at the center of the applet. The message is passed as a parameter to the applet.
import java.awt.*;
import java.applet.*;
/*
<applet code="ass8a1.class" width=400 height=200>
</applet>
*/
public class ass8a1 extends Applet
{
String msg;
public void init()
{
Font f=new Font("big",Font.BOLD|Font.ITALIC,24);
setFont(f);
setBackground(Color.orange);
msg=getParameter("msg");
if(msg == null)
{
}
msg="No One Msg Passed";
}
public void paint(Graphics g)
{
int x,y;
Dimension d;
d=this.getSize();
FontMetrics f=g.getFontMetrics();
x=(d.width-f.stringWidth(msg))/2;
y=(d.height-f.getHeight())/2;
g.drawString(msg,x,y);
}
}
No comments:
Post a Comment