简体   繁体   English

程序已编译,但无法运行

[英]Program compiles, but won't run

Let's keep it simple. 让我们保持简单。 My code compiles, and when I run it (using java CLASSNAME ), this is my command prompt error: 我的代码经过编译,当我运行它(使用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)

For reference, this is the code at line 147 供参考,这是第147行的代码

    Map.setBackground(new Color(0,0,0,0));

And the code at line 69 以及第69行的代码

    Game.setContentPane(new RPG());

They are two different JFrames, but they are conflicting? 它们是两个不同的JFrame,但是它们有冲突吗? 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。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM