[英]Program compiles, but won't run
讓我們保持簡單。 我的代碼經過編譯,當我運行它(使用java CLASSNAME
)時,這是我的命令提示符錯誤:
Exception in thread "main" java.awt.IllegalComponentStateException: The frame is
decorated
at java.awt.Frame.setBackground(Frame.java:986)
at RPG.<init>(RPG.java:147)
at RPG.main(RPG.java:69)
供參考,這是第147行的代碼
Map.setBackground(new Color(0,0,0,0));
以及第69行的代碼
Game.setContentPane(new RPG());
它們是兩個不同的JFrame,但是它們有沖突嗎? 這是我的原始代碼段:
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception unused) { }
Game.setTitle(" ");
Game.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Game.setContentPane(new RPG());
Game.setDefaultLookAndFeelDecorated(true);
Game.pack();
Game.setSize(850,500);
Game.setLocationRelativeTo(null);
Game.setResizable(false);
}
public RPG(){
sgame = 1;
Game.setVisible(false);
JFrame Map = new JFrame();
Map.setTitle("Map");
Map.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Map.setBackground(new Color(0,0,0,0));
Map.setUndecorated(true);
JLabel testLabel = new JLabel(new ImageIcon(getClass().getResource("Title.png")));
Map.add(testLabel);
Map.setSize(200,200);
Map.setLocation(0, 250);
Map.setResizable(false);
Map.setVisible(true);
Launcher();
}
抱歉,如果不清楚,或者我沒有太多道理,我只想知道為什么我無法啟動我的程序。
在調用.setBackground()之前,嘗試將Map
設置為Undecorated。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.