Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.*;
import java.awt.geom.Rectangle2D;

public class Main {
    public static void drawCenteredString(Graphics g, String str, int x, int y) {
        FontMetrics metrics = g.getFontMetrics(g.getFont());
        Rectangle2D rect = metrics.getStringBounds(str, g);
        int w = (int) (rect.getWidth());
        int h = (int) (rect.getHeight());
        g.drawString(str, x - w / 2, y + h / 2);
    }
}