Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JPanel没有出现在EclipseIDE中?_Java_Eclipse_Macos_Swing - Fatal编程技术网

Java JPanel没有出现在EclipseIDE中?

Java JPanel没有出现在EclipseIDE中?,java,eclipse,macos,swing,Java,Eclipse,Macos,Swing,我是一个新手程序员,最近一直在尝试GUI。我一直在学校的电脑(WindowsXP、TextPad)上开发一个应用程序,它们在上面编译并运行良好。然而,当我在家用计算机(MacOSMountainLion,Eclipse)上运行完全相同的代码时,JPanel似乎没有正确地添加到JFrame中。我有以下课程 Main.java: public class Main { public static void main( String[] args ) { new Frm();

我是一个新手程序员,最近一直在尝试GUI。我一直在学校的电脑(WindowsXP、TextPad)上开发一个应用程序,它们在上面编译并运行良好。然而,当我在家用计算机(MacOSMountainLion,Eclipse)上运行完全相同的代码时,JPanel似乎没有正确地添加到JFrame中。我有以下课程

Main.java:

public class Main {
    public static void main( String[] args ) {
        new Frm();
    } // end of method main()
} // end of class Main
Frm.java:

import javax.swing.JFrame;

@SuppressWarnings("serial")
public class Frm extends JFrame {

    private final int HEIGHT = 400;
    private final int WIDTH = 600;

    public Frm() {
        setSize(WIDTH, HEIGHT);
        setTitle("SHREK");  
        setVisible(true);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        getContentPane().add(new Pnl());
    } // end of constructor

} // end of class Frm
Pnl.java:

import java.awt.Color;
import java.awt.Graphics;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JPanel;
import javax.swing.BorderFactory;

@SuppressWarnings("serial")
public class Pnl extends JPanel {
    public Pnl() {
        BorderFactory.createLineBorder(Color.BLACK, 5);
        setBackground(Color.BLACK); 
    } // end of constructor
} // end of class Pnl
试着打电话

setVisible(true);
之后

getContentPane().add(new Pnl());