0

I've tried running both an Applet and a JFrame following certain YouTube tutorials, but when they run on my computer, they ignore the size I specify for the window, and forcibly open maximized and will simply not resize.

Here's a simple example Applet I ran:

package pong;

import java.applet.Applet;
import java.awt.*;

public class Pong extends Applet{
    final int WIDTH = 700, HEIGHT = 500;

    public void init() {
        this.resize(WIDTH, HEIGHT);
    }

    public void paint(Graphics g) {
    }

    public void update(Graphics g) {
    }
}

I cannot resize the window/panel. I don't know if this is an issue with my computer Yoga 2 Pro.

Any help is greatly appreciated.

EDIT: I think perhaps I wasn't clear enough. I am simply not managing to correctly view ANY JPanel or Applet. They display on my Yoga 2 Pro as maximized, and with their content being strange as well. In this example I'm simply trying to get a 700x500 window, but Java ignores this fact on my computer. Thanks

3
  • The code is working fine. I mean to say the resize() method works fine. Also you can use setSize(WIDTH, HEIGHT) to set the size of applet instead of resize(). Commented Dec 27, 2015 at 15:57
  • When do you need the window to resize?
    – Perdomoff
    Commented Dec 27, 2015 at 16:11
  • this.resize(WIDTH, HEIGHT); Don't attempt this in an applet. The applet is typically a guest in a web page, and its size is set by the HTML. A good time to get used to that is when developing the applet. As an aside: Why code an applet? If it is due to the teacher specifying it, please refer them to Why CS teachers should stop teaching Java applets. Commented Dec 28, 2015 at 4:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.