Results 1 to 6 of 6

Thread: How to Make Frames or Main Windows in Java?

  1. #1
    Join Date
    Aug 2006
    Posts
    181

    How to Make Frames or Main Windows in Java?

    Hi friends,
    I am new to the Java programming language. I have just completed the C++ programming language and recently turned to the Java.!! The reason for posting, is that I want some help from you guys to tell me about the Main Windows or Frames in Java.!! Can anyone tell me how to make frames (main windows) in Java..?? Please help me soon as possible.!!
    QTechnology Ultra-Quiet ATX PSU 460W I MSI K8N Neo4-F I AMD Opteron 144 CABNE0545 2.66Ghz I 2 x 512MB RAM I 380GB Maxtor SATAI Raid0 Hard Drive I 40GB Maxtor IDE Hard Drive I Nvidia GeForce 7900GTX I Win XP Home Service Pack 2 I Soundblaster Xtreme Fidelity Fatal1ty I Mercury Home Theater HT-4500

  2. #2
    Join Date
    Nov 2008
    Posts
    996

    Re: How to Make Frames or Main Windows in Java?

    You should know that a Frame is a top-level window with a title and a border. The dimensions of the border area may be obtained using the getInsets method. Most Swing applications present their primary GUIs within a JFrame in the API reference documentation. You can use an internal frame to make a window that appears within another window. A frame, implemented as an instance of the JFrame class. Even the applets sometimes use frames.

  3. #3
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to Make Frames or Main Windows in Java?

    You would understand more better if you have a look on the example that I provided down. In that example I have explained a sample of a code that creates and set up a frame. Here is the code :
    Code:
    JFrame.setDefaultLookAndFeelDecorated(true);
    
    JFrame frame = new JFrame("FrameDemo");
    
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
    
    frame.pack();
    
    frame.setVisible(true);

  4. #4
    Join Date
    Mar 2008
    Posts
    672

    Re: How to Make Frames or Main Windows in Java?

    You said that you want to create a frame with a custom icon and with window. The following sample of the code does the same :
    Code:
    JFrame.setDefaultLookAndFeelDecorated(true);
    
    JFrame frame = new JFrame("A window");
    
    frame.setIconImage(new ImageIcon(imgURL).getImage());
    Hope that the above code helps you to create a attractive window.

  5. #5
    Join Date
    Aug 2006
    Posts
    235

    Re: How to Make Frames or Main Windows in Java?

    You should also be knowing the methods related with the frame. There are some methods that you call are defined by the java.awt.Frame, java.awt.Window and java.awt.Component classes, which descends the JFrame. The listener's implementation makes the program exit when the user closes the frame. JFrame itself is a subclass of java.awt.Frame to which it adds support for interposing input. Instead of writing a window listener, JFrame lets you customize window closing behavior by calling the setDefaultCloseOperation method. Also due to the setJMenuBar method, the swing menus work best in a JFrame.
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to Make Frames or Main Windows in Java?

    I have provided you with the code that creates a bordered JPanel to use as the frame's content pane and in which the panel contains two labels and a button. Here is the code :
    Code:
    public static void main(String[] args) {
        JFrame f = new JFrame("Which is that Car?");
        JPanel contentPane = new JPanel();
        f.setContentPane(contentPane);
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        contentPane.setBorder(BorderFactory.createEmptyBorder(30,30,30,30));
    
        contentPane.add(intro);
        contentPane.add(name);
        contentPane.add(Box.createRigidArea(new Dimension(0,15)));
        contentPane.add(button);
        ...
    }

Similar Threads

  1. Are you going to make Windows 8 RTM as your main OS?
    By OSzilla in forum Polls & Voting
    Replies: 1
    Last Post: 05-09-2012, 12:21 PM
  2. Java main class not found
    By Rily in forum Software Development
    Replies: 6
    Last Post: 13-08-2010, 10:21 AM
  3. Explain main method in java
    By Angelica Maria in forum Software Development
    Replies: 5
    Last Post: 10-03-2010, 01:18 PM
  4. Why main method is static in java?
    By MKAIF in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 04:20 PM
  5. Restart main in java
    By cyber-noob in forum Software Development
    Replies: 4
    Last Post: 24-11-2009, 05:31 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,711,669,838.13091 seconds with 16 queries