import java.awt.*; import java.awt.event.*; import javax.swing.*; class TestPanel extends JPanel { public void paintComponent (Graphics g) { super.paintComponent (g); // Draw the string "Hello World!" at location (50,50) g.drawString ("Hello World!", 50, 50); } } class TestFrame extends JFrame implements WindowListener { public TestFrame () { // Set the title, size and Window-closing event listener. setTitle ("Hello World Window"); setSize (500, 300); addWindowListener (this); // Make a panel instance and put that in the frame. TestPanel p = new TestPanel (); getContentPane().add(BorderLayout.CENTER, p); // Make the frame visible. setVisible (true); } // Implementation of WindowListener interface: public void windowClosing(WindowEvent e) { System.exit(0); } // Empty implementations of methods we don't need. public void windowOpened(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowActivated(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} } public class HelloWorldWindow extends JFrame { public static void main (String[] argv) { // Fire up the frame. TestFrame f = new TestFrame (); } }