Java Applet Windows size in Eclipse

守給你的承諾、 提交于 2019-12-30 10:47:06

问题


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,

  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.

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


回答1:


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.

Hope it will helpful: a similar issue




回答2:


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.




回答3:


try this inside the paint method for example

this.setSize(300, 300);


来源:https://stackoverflow.com/questions/19367320/java-applet-windows-size-in-eclipse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!