我想尝试使用JFrame
,并且我尝试了互联网和视频教程上的许多代码示例(如下所示)。
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class test extends JFrame {
public static void main(String[] args){
//1. Create the frame.
JFrame frame = new JFrame("FrameDemo");
//2. Optional: What happens when the frame closes?
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//3. Create components and put them in the frame.
JLabel emptyLabel = new JLabel("BLAHBLAHBHALBAHLKKDJF");
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
//4. Size the frame.
frame.pack();
//5. Show it.
frame.setVisible(true);
}
}
Eclipse 没有向我显示代码中的任何错误,但是当我运行它时,框架总是向我显示下面的图像(数字列表)。我完全不明白为什么。
Eclipse 中的运行按钮上显示黄色文字“Run AnnotatedMemoryPanel”。
我在互联网上没有找到任何关于此的讨论。 希望有人能解释我出了什么问题。
最佳答案
您可能偶然运行了一些完全不同的应用程序,而不是您发布源代码的应用程序。在 Eclipse 中,尝试右键单击源代码,然后选择 Run As
,然后选择 Java Application
。快捷键是 Shift + Alt + X J。
关于java - JFrame : it shows a list of number instead of the image 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39015056/