JWindow and JFrame Component in Java

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:
  1. import javax.swing.*; // used to access the JFrame, JWindow, and JPanel class
  2. 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.
  1. JFrame frame = new JFrame("This is a Frame");
  2. JWindow window = new JWindow();
  3. JPanel panel = new JPanel();
4. We will add the JPanel component into the window, and it will have a default BorderLayout of Center position.
  1. window.getContentPane().add(panel, "Center");
Now, we will create a FlowLayout for the panel and a Label inside the panel.
  1. panel.setLayout(new FlowLayout());
  2. panel.add(new Label("This is a Window"));
5. Lastly, we will set the size and location of the Frame and the Window.
  1. frame.setSize(300, 300);
  2. frame.setLocation(100, 100);
  3.  
  4. window.setSize(300, 300);
  5. window.setLocation(500, 100);
Then, we will set the visibility to True for the two components to be seen by the user.
  1. frame.setVisible(true);
  2. window.setVisible(true);
Frame: output Window: output Output: output Here's the full code of this tutorial:
  1. import javax.swing.*; // used to access the JFrame, JWindow, and JPanel class
  2. import java.awt.*; // used to access the FlowLayout class
  3.  
  4.  
  5. public class jWindowComponent {
  6. public static void main(String[] args) {
  7. JFrame frame = new JFrame("This is a Frame");
  8. JWindow window = new JWindow();
  9. JPanel panel = new JPanel();
  10.  
  11. window.getContentPane().add(panel, "Center");
  12.  
  13. panel.setLayout(new FlowLayout());
  14. panel.add(new Label("This is a Window"));
  15.  
  16. frame.setSize(300, 300);
  17. frame.setLocation(100, 100);
  18.  
  19. window.setSize(300, 300);
  20. window.setLocation(500, 100);
  21.  
  22. frame.setVisible(true);
  23. window.setVisible(true);
  24. }
  25. }
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

Add new comment