import java.awt.*; // Graphics, Color, and Font import javax.swing.*; // JApplet and JPanel public class HelloApplet4 extends JApplet { public void init() { getContentPane().add(new MsgPanel(500, Color.yellow)); //500 ms } public static void main(String[] args) { JFrame f = new JFrame("I am an Appication"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); HelloApplet4 ha = new HelloApplet4(); // create an instance of HelloApplet4 f.getContentPane().add(ha, BorderLayout.CENTER); ha.init(); ha.start(); f.setSize(350,130); f.setVisible(true); } } class MsgPanel extends JPanel implements Runnable { private boolean show = true; private Thread thrd = null; private int msec = 1000; private Color c; public MsgPanel(int ms, Color c) { msec = ms; this.c = c; thrd = new Thread(this); thrd.start(); } public void run() { while(true) { repaint(); try { thrd.sleep(msec); } catch (InterruptedException ex) { System.out.println(ex); } } } public void paintComponent(Graphics g) { super.paintComponent(g); // clear VA g.setFont( new Font("Arial", Font.BOLD, 16) ); setBackground(c); if(show) g.drawString("Hello", 100, 50); show = !show; } } // Chung (c) 2000