Java Swing display Basic Window example





Hey guys in this post, we will discuss how to display the basic window using Java Swing.

Example


import javax.swing.JFrame;

public class BasicWindow extends JFrame{

public static void main(String[] args) {
		
		UserInput userInput = new UserInput();
		userInput.setVisible(true);
		
	}
	
	public BasicWindow() {
		setSize(600, 600);
		setTitle("Basic Window");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}
	
}

Output:

We will extend the class with the JFrame class, it is a top-level container/widget, it is used to place other widgets.

setSize(), Resizes this component so that it has width 600 and height 600.

setTitle(), Sets the title for this frame to the specified string.

setDefaultCloseOperation(), we will set the default close operation to EXIT_ON_CLOSE, which will close when the user clicks on the close button.



About the author

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *