This is a tutorial in which we will going to create a program that will have a JWindow and JFrame Component in Java. We will first differentiate the two components. The
JFrame can be a container of other components, has title and border, and has buttons for minimize, maximize, and close. Unlike JFrame, a
JWindow can also hold other components but it has no title and border, and no minimize, maximize, and close button.
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of
jWindowComponent.java.
2. Import the following packages:
import javax.swing.*; // used to access the JFrame, JWindow, and JPanel class
import java.awt.*; // used to access the FlowLayout class
3. Initialize your variable in your Main, variable
frame for JFrame, variable
window for JWindow, and variable
panel for JPanel.
4. We will add the JPanel component into the window, and it will have a default BorderLayout of Center position.
window.getContentPane().add(panel, "Center");
Now, we will create a FlowLayout for the panel and a Label inside the panel.
panel.
add(new Label("This is a Window"));
5. Lastly, we will set the size and location of the Frame and the Window.
frame.setSize(300, 300);
frame.setLocation(100, 100);
window.setSize(300, 300);
window.setLocation(500, 100);
Then, we will set the visibility to True for the two components to be seen by the user.
frame.setVisible(true);
window.setVisible(true);
Frame:
Window:
Output:
Here's the full code of this tutorial:
import javax.swing.*; // used to access the JFrame, JWindow, and JPanel class
import java.awt.*; // used to access the FlowLayout class
public class jWindowComponent {
public static void main
(String[] args
) {
window.getContentPane().add(panel, "Center");
panel.
add(new Label("This is a Window"));
frame.setSize(300, 300);
frame.setLocation(100, 100);
window.setSize(300, 300);
window.setLocation(500, 100);
frame.setVisible(true);
window.setVisible(true);
}
}
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:
[email protected]
Add and Follow me on Facebook:
https://www.facebook.com/donzzsky
Visit and like my page on Facebook at:
https://www.facebook.com/BermzISware