A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Swing / AWT / SWT
Author
Sinple GUI Program which uses the BorderLayout.
Priyank Kalgaonkar
Greenhorn
Joined: Sep 02, 2012
Posts: 1
posted
Sep 02, 2012 17:32:27
0
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:
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!
Untitled1.png
This is what my out is supposed to be.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
Sep 03, 2012 19:10:11
0
another time waster
http://www.javaprogrammingforums.com/whats-wrong-my-code/17482-sinple-gui-program-uses-borderlayout.html
Ranganathan Kaliyur Mannar
Bartender
Joined: Oct 16, 2003
Posts: 921
2
I like...
posted
Sep 04, 2012 01:38:07
0
Hi Priyank,
Welcome to the Ranch!
Please
BeForthrightWhenCrossPostingToOtherSites
.
Click on the link to understand what it is and how it can help everyone help you.
Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Aleksey Vladimirovich
Ranch Hand
Joined: Sep 05, 2012
Posts: 56
posted
Sep 05, 2012 11:21:49
0
Try something like this:
import java.awt.*; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; public class GUI extends JFrame { public GUI() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); } JPanel mainPane = new JPanel(new GridLayout(1, 2, 0, 0)); JPanel westPane = new JPanel(new FlowLayout()); westPane.setBackground(Color.PINK); westPane.add(new JButton("Java")); westPane.add(new JButton("Programming")); mainPane.add(westPane); JPanel eastPane = new JPanel(new FlowLayout()); eastPane.setBackground(Color.YELLOW); eastPane.add(new JButton("Is Not So Easy.")); mainPane.add(eastPane); this.getContentPane().add(mainPane, BorderLayout.CENTER); JPanel southPane = new JPanel(new FlowLayout()); southPane.setBackground(Color.BLUE); southPane.add(new JButton("Linear Data Structures !")); this.getContentPane().add(southPane, BorderLayout.SOUTH); } public static void main(String[] args) { GUI frame = new GUI(); frame.setTitle("EECS 1570"); frame.setSize(400, 250); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
If you need pink and yellow areas to be of different sizes, try to apply a different
LayoutManager
for mainPane.
I agree. Here's the link:
http://aspose.com/file-tools
subject: Sinple GUI Program which uses the BorderLayout.
Similar Threads
How can I get my temperature converter program to display negative numbers
How to get this attached design using Layout Managers - sans GroupLayout
trouble with layouts
White bars on bottom and top of JFrame
about object serialization
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter