import javax.swing.*; import java.awt.*; class JFlash extends JFrame implements Runnable { private JLabel label; public JFlash(String aString) { super(aString); } public void run() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add the ubiquitous "Hello World" label. label = new JLabel(); label.setFont(label.getFont().deriveFont((float)44)); label.setOpaque(true); label.setBackground(new Color(0,51,0)); label.setForeground(Color.RED); label.setHorizontalAlignment(SwingConstants.CENTER); getContentPane().add(label); //Display the window. pack(); setSize(500,200); setVisible(true); } public void flash(final String aString) { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { label.setText(aString); }}); Thread.sleep(1000); SwingUtilities.invokeAndWait(new Runnable() { public void run() { label.setText(""); }}); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { SwingUtilities.invokeLater(new JFlash("Cremona")); } }