I'm trying to draw a string at the center of an applet. The problem is that it's STARTING to draw at the center of the applet and going off to the right. I need for the center of the string to be centered. Here's my code so far:
/**
* @(#)CIS226_Assignment_03_centerString.java
*
* CIS226_Assignment_03_centerString Applet application
*
* @author
* @version 1.00 2010/9/24
*/
import java.awt.*;
import java.applet.*;
public class CIS226_Assignment_03_centerString extends Applet {
public void init() {
}
public void centerString(Graphics g)
{
int x = getSize().width;
int y = getSize().height;
int c1 = x/2;
int c2 = y/2;
g.drawString("Welcome to Java!!", c1, c2 );
}
public void paint(Graphics g) {
centerString(g);
}
}
Can anyone give me some insight as to what I'm doing wrong?