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.font.FontRenderContext;
import java.awt.geom.Rectangle2D;

public class Main {
    public static final Color TEXT_SHADOW_COLOR = new Color(255, 255, 255);

    public static void drawCenteredShadowText(Graphics2D g2, String s, int x, int y) {
        drawCenteredShadowText(g2, s, x, y, TEXT_SHADOW_COLOR);
    }

    public static void drawCenteredShadowText(Graphics2D g2, String s, int x, int y, Color shadowColor) {
        FontRenderContext frc = g2.getFontRenderContext();
        Rectangle2D bounds = g2.getFont().getStringBounds(s, frc);
        int leftX = (int) (x - (float) bounds.getWidth() / 2);
        drawShadowText(g2, s, leftX, y, shadowColor, 1);
    }

    public static void drawShadowText(Graphics2D g2, String s, int x, int y) {
        drawShadowText(g2, s, x, y, TEXT_SHADOW_COLOR, 1);
    }

    public static void drawShadowText(Graphics2D g2, String s, int x, int y, Color shadowColor, int offset) {
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        Color c = g2.getColor();
        g2.setColor(shadowColor);
        g2.drawString(s, x, y + offset);
        g2.setColor(c);
        g2.drawString(s, x, y);
    }
}