package chapter10; import java.awt.Graphics; import java.awt.Color; import javax.swing.*; public class DrawHello extends JFrame { public DrawHello()// Default constructor { setTitle("Draw Hello on a JPanel"); getContentPane().add(new MsgPanel()); } public static void main(String[] args) { DrawHello frame = new DrawHello(); frame.setSize(250,130); frame.setVisible(true); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); } } class MsgPanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); // to clear the viewing area g.drawString("Hello", 100, 50); } } // chung