Tuesday, October 19, 2021

A Window Frame In Java

There are two kinds of programs in Java. One that runs on the commandline. The other runs as a GUI. Today we'll be focusing on GUIs.

In order to work with a GUI, first you need to create a window. We use a JFrame in order to do this.


import javax.swing.JFrame;

public class Window extends JFrame {

public Window() {
super("My Window");
setSize(640, 480);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}

public static void main(String[] args) {
new Window();
}
}

No comments:

Post a Comment

Ever feel like no one is listening?

 Ever have that feeling that no one is listening to you? Yeah, that feeling. It can be a strong feeling to have, a hurtful feeling also. The...