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
resize()
method works fine. Also you can usesetSize(WIDTH, HEIGHT)
to set the size of applet instead ofresize()
.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.