Eclipse 中的 Java Applet Windows 大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19367320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 16:31:33  来源:igfitidea点击:

Java Applet Windows size in Eclipse

javaapplet

提问by Sufiyan Ghori

I am trying to set the size of an Applet Window to 500 by 500, but I couldn't be able to achieve that. Here is my code,

我试图将 Applet Window 的大小设置为 500 x 500,但我无法实现。这是我的代码,

  public void init() { 
    // Start Screen Color 
    setBackground(Color.RED);
    this.setSize(new Dimension(500,500));

    width=getSize().width;
    height=getSize().height;

    running=false;
    repaint();
    offscreenImage = createImage(width,height);
    offscreenGraphics = offscreenImage.getGraphics();
    addKeyListener(this);    
    addFocusListener(this);

    waitingForSpace=false;

    repaint();
  }

When I pressed CTRL+F11 in Eclipse I get the output Window with size 200 by 200, Why I try to run the program like 5 to 10 times, sometimes the window returns with the 500 by 500 size while some time the window size is 200 by 200.

当我在 Eclipse 中按 CTRL+F11 时,我得到大小为 200 x 200 的输出窗口,为什么我尝试运行程序 5 到 10 次,有时窗口返回 500 x 500 大小,而有时窗口大小为 200到 200。

I do not understand why the size of the window i changing since I am not changing any code at all. I want the size to remain at 500 by 500

我不明白为什么要更改窗口的大小,因为我根本没有更改任何代码。我希望大小保持在 500 x 500

采纳答案by guanda

If you use eclipse, you can change applet size from the "run configuration" Java Applet->Parameters". I think that's the problem, because the default value of java applet size in eclipse is 200*200.

如果你使用eclipse,你可以从“运行配置”Java Applet->Parameters中改变applet size,我觉得是这个问题,因为eclipse中java applet size的默认值是200*200。

Hope it will helpful: a similar issue

希望它会有所帮助: 一个类似的问题

回答by Hassen Ch.

try this inside the paint method for example

例如在paint方法中试试这个

this.setSize(300, 300);

回答by enivaldo bonelli

To change the size of the Applet Window, without looking for the eclipse .html is to choose "Run Configurations" in the "Run, '>' icon options " in the eclipse panel. In the configurations choose "Parameters" and set the size of the applet in the two boxes available for 'height' and 'length.' You may leave the box 'name' unfilled.

要更改Applet Window 的大小,无需查找eclipse .html 就是在eclipse 面板的“运行,'>' 图标选项”中选择“运行配置”。在配置中选择“参数”并在“高度”和“长度”两个可用框中设置小程序的大小。您可以不填写“名称”框。