Here you can find the source of drawStringOnScreen(String s, Color color, long milseconds)
Parameter | Description |
---|---|
s | a parameter |
color | a parameter |
milseconds | a parameter |
public static void drawStringOnScreen(String s, Color color, long milseconds)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Window; public class Main { /**//from w w w.jav a2 s .c o m * * @param s * @param color * @param milseconds */ public static void drawStringOnScreen(String s, Color color, long milseconds) { Thread t = new Thread(() -> { Window w = new Window(null) { @Override public void paint(Graphics g) { final Font font = getFont().deriveFont(48f); g.setFont(font); g.setColor(color); final String message = s; FontMetrics metrics = g.getFontMetrics(); g.drawString(message, (getWidth() - metrics.stringWidth(message)) / 2, (getHeight() - metrics.getHeight()) / 2); } @Override public void update(Graphics g) { paint(g); } }; w.setAlwaysOnTop(true); w.setBounds(w.getGraphicsConfiguration().getBounds()); w.setBackground(new Color(0, true)); w.setVisible(true); try { Thread.sleep(milseconds); } catch (InterruptedException ex) { } w.dispose(); }); t.start(); } }