Results 1 to 6 of 6

Thread: What is the use of JFrame class?

  1. #1
    Join Date
    Dec 2009
    Posts
    38

    What is the use of JFrame class?

    Hi friends,

    I need your help to get solution over my query about the java concepts. I don't have sound knowledge about the java class concepts. I want to be aware about the JFrame class of the java language. I also want to be aware about it's various methods. If you have knowledge about the JFrame class of java, then please let me know with suitable example for the same. I would appreciate your any help over JFrame class.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: What is the use of JFrame class?

    The JFrame class is slightly incompatible with Frame. Like all other JFC/Swing top-level containers, a JFrame contains a JRootPane as its only child. The content pane provided by the root pane should, as a rule, contain all the non-menu components displayed by the JFrame. This is different from the AWT Frame case. Unlike a Frame, a JFrame has some notion of how to respond when the user attempts to close the window. The default behavior is to simply hide the JFrame when the user closes the window.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: What is the use of JFrame class?

    Hi,

    Please refer following example of JFrame class of java. Which containse the code for resizing a JFrame"
    Code:
    import javax.swing.JButton;
    import javax.swing.JFrame;
    
    public class JFrameDemo {
      public static void main(String[] argso) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame VY = new JFrame();
        VY.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        VY.setTitle("JFrame Test");
        VY.setLayout(new GridLayout(3, 2));
        VY.add(new JLabel("First Name:"));
        VY.add(new JTextField());
        VY.add(new JLabel("Last Name:"));
        VY.add(new JTextField());
        VY.add(new JButton("Register"));
    
        int VYWidth = 300;
        int VYHeight = 200;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        VY.setBounds((int) screenSize.getWidth() - VYWidth, 0, VYWidth, VYHeight);
        VY.setVisible(true);
      }
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What is the use of JFrame class?

    To use the JFrame class, before that you need to be aware about following it's methods:
    • setRootPaneCheckingEnabled(boolean bln)
    • setRootPane(JRootPane jrt)
    • setLayout(LayoutManager mgr)
    • setDefaultLookAndFeelDecorated(boolean defaultLookDecorated)
    • setGlassPane(Component glsPane)
    • processWindowEvent(WindowEvent wevn)

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: What is the use of JFrame class?

    Hello friend,

    Below I have given example of JFrame class. In which the output will show you the instance of JFrame class:
    Code:
    import javax.swing.JLabel;
    import javax.swing.JFrame;
    
    public class JFramePackDM {
    
      public static void main(String[] argsd)
    
     {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame VLP = new JFrame();
        VLP.setTitle("My First Swing Application");
        VLP.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JLabel label = new JLabel("Welcome");
        VLP.add(label);
        VLP.pack();
        VLP.setVisible(true);
      }
    }

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: What is the use of JFrame class?

    Hi,

    Please refer following various constructors of JFrame class:
    1. JFrame(String ttl, GraphicsConfiguration gc1): This constructor used for the creation of JFrame with specified GraphicsConfiguration and title.
    2. JFrame(GraphicsConfiguration gc1): This constructor used for the creation of JFrame with particular GraphicsConfiguration.
    3. JFrame(): This constructor used for the creation of normal JFrame.
    4. JFrame(String ttl): This constructor used for the creation of JFrame with particular text.

Similar Threads

  1. Pass JFrame to actionlistener
    By Freeza 2 in forum Software Development
    Replies: 5
    Last Post: 23-08-2010, 06:30 PM
  2. How to set the background color of JFrame?
    By kamina23 in forum Software Development
    Replies: 4
    Last Post: 13-02-2010, 06:42 PM
  3. Anchoring a JFileChooser in a JFrame
    By technika in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 11:27 AM
  4. JFrame window problem
    By cyber-noob in forum Software Development
    Replies: 2
    Last Post: 09-11-2009, 11:45 AM
  5. How to pass object to jframe
    By Brunoz in forum Software Development
    Replies: 3
    Last Post: 06-08-2009, 11:36 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,281,453.48963 seconds with 17 queries