Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- /* Using Applet Dimension */
- /* Syntax
- Dimension(Dimension d)
- Dimension(int w, int h)
- */
- import java.applet.Applet;
- import java.awt.Graphics;
- import java.awt.*;
- import java.awt.Color;
- /*
- <applet code = "Applet06" width = 500 height = 300>
- </applet>
- */
- public class Applet06 extends Applet
- {
- public void paint(Graphics g)
- {
- int x,y;
- String s = "Hello World...";
- Dimension d = getSize();
- Font f = new Font("Arial",Font.BOLD,24);
- g.setFont(f);
- FontMetrics fm = g.getFontMetrics();
- x = d.width/2 - fm.stringWidth(s)/2;
- y = d.height/2 - fm.getHeight();
- g.drawString(s,x,y);
- }
- }

Post new comment