Search code examples
javaapplet

Java Applet Windows size in Eclipse


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


Solution

  • 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