把 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;}
{
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;}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货