把 NotHelloWorldPanel , NotHelloWorldFrame 从 NotHelloWorld 中移出即可public class NotHelloWorld 
{
public static void main (String[] args)
{
NotHelloWorldFrame Nframe = new NotHelloWorldFrame();
Nframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Nframe.show();
}}class NotHelloWorldFrame extends JFrame 
{
public NotHelloWorldFrame ()
{
setTitle("NotHelloWorld");
setSize(WIDTH,HEIGHT);
setLocation(200,300);

//addpanel to frame

NotHelloWorldPanel Npanel = new NotHelloWorldPanel();
Container contentPanel = getContentPane();
contentPanel.add(Npanel);
}
public static final int WIDTH = 300;
public static final int HEIGHT = 200;
}  class NotHelloWorldPanel extends JPanel {
   public void paintComponent(Graphics g)
   {
   super.paintComponent(g);
   g.drawString("Not a Hello, World program",MESSAGE_X,MESSAGE_Y);
   }
   public static final int MESSAGE_X = 75;
   public static final int MESSAGE_Y = 100;}