Let's keep it simple. My code compiles, and when I run it (using java CLASSNAME
), this is my command prompt error:
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)
For reference, this is the code at line 147
Map.setBackground(new Color(0,0,0,0));
And the code at line 69
Game.setContentPane(new RPG());
They are two different JFrames, but they are conflicting? Here is the entire snippet from my source:
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();
}
Sorry if it seems unclear or if I am not making much sense, I'd just like to know why I can't launch my program.
在调用.setBackground()之前,尝试将Map
设置为Undecorated。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.