Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Sinple GUI Program which uses the BorderLayout.

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face Sinple GUI Program which uses the BorderLayout.

    I need to write a Java program to display a screen like the following screen, which uses the BorderLayout.

    This is what my output is supposed to be:
    Untitled1.png or View Here: https://www.dropbox.com/s/u1pqz588b8cofxo/Untitled1.png

    I tried writing the code for this program. But I am not able to do so. Following is my code:

    import java.awt.BorderLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
     
    public class GUI extends JFrame 
    {
    	public GUI()
    	{
    		setLayout(new BorderLayout(1000,2000));
     
    		add(new JButton("Java"), BorderLayout.NORTH);
    		add(new JButton("Programming"), BorderLayout.CENTER);
    		add(new JButton("Is Not So Easy"), BorderLayout.NORTH);
    		add(new JButton("Linear Data Structers!"), BorderLayout.SOUTH);
    	}
     
    	public static void main(String[] args)
    	{
    		GUI frame = new GUI();
    		frame.setTitle("EECS 1570");
    		frame.setSize(600,400);
    		frame.setLocationRelativeTo(null);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setVisible(true);
    	}
    }

    Please can you help me get the output like the one in the attached picture file? Thanks for your help. Much appreciated!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Sinple GUI Program which uses the BorderLayout.

    First problem I see is that the code adds two components to the same area: NORTH.
    If you want those two components to both be there, add them to a JPanel and add it to NORTH.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sinple GUI Program which uses the BorderLayout.

    Okay! Thanks. I got it. Appreciate your help

Similar Threads

  1. Replies: 1
    Last Post: July 8th, 2012, 10:23 AM
  2. BorderLayout and getHeight/getWidth
    By DOLZero in forum Java Theory & Questions
    Replies: 2
    Last Post: May 5th, 2012, 08:59 AM
  3. [SOLVED] JPanel inside CENTER of BorderLayout is given GRID LAYOUT
    By JonLane in forum AWT / Java Swing
    Replies: 9
    Last Post: February 25th, 2012, 12:20 PM
  4. Replies: 6
    Last Post: February 21st, 2012, 09:41 PM
  5. BackgroundPanel.java cannot be placed in BorderLayout.NORTH
    By chopficaro in forum AWT / Java Swing
    Replies: 7
    Last Post: August 31st, 2010, 06:27 PM