package Jframe;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class JavaWindows {
public static void main(String args[]) {
JFrame Window = new JFrame();
JLabel Label = new JLabel("test");
JPanel Panel = new JPanel();
ImageIcon icon = new ImageIcon("Heart.png");
Window.setIconImage(icon.getImage());
Window.add(Panel);
Window.add(Label);
Window.setSize(500,750);
Panel.setSize(500, 900);
Window.getContentPane().setBackground(Color.PINK);
Window.pack();
}
}
大约 10 分钟前,这段代码有效。它制作了一个大约 100,100 的窗户,带有尺寸正确的 500,900 面板。窗口不是我指定的 500,750,我不知道那里出了什么问题,但突然间窗口无法在 Eclipse 中运行。我删除了窗口包((;并重新输入它现在它坏了。有什么想法吗?
你必须设置框架的可见性
window.setVisible(true);