Welcome to Dream.In.Code
Become a Java Expert!

Join 150,124 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,026 people online right now. Registration is fast and FREE... Join Now!




help with a boarder layout

 
Reply to this topicStart new topic

help with a boarder layout

safaboi
25 Jun, 2008 - 05:47 PM
Post #1

New D.I.C Head
*

Joined: 26 Feb, 2007
Posts: 12


My Contributions
I'm just trying to create a GUI program that displays 5 words in a border layout, i keep getting errors, what am i doing wrong?


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;

public class Bordergrid extends JFrame {

private final String WINDOW_TITLE = "2nd example";
private final int WINDOW_WIDTH = 300; //window width
private final int WINDOW_HEIGHT = 100; // window height

JLabel liftLabel = new JLabel("Lift");
JLabel thrustLabel = new JLabel ("Thrust");
JLabel flightLabel = new JLabel ("The Forces of Flight");
JLabel dragLabel = new JLabel ("Drag");
JLabel weightLabel = new JLabel ("Weight");
JPanel mainPanel= new JPanel();
JPanel northPanel= new JPanel();
JPanel southPanel= new JPanel();
JPanel eastPanel= new JPanel();
JPanel westPanel= new JPanel();
JPanel centerPanel= new JPanel();

public Bordergrid(){
setTitle(WINDOW_TITLE);
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanels();
setVisible(true);
}

/** the main method just does an anoymous instantiation of the Bordergrid
class. THe constructor takes over and builds the display.
*/

public static void main(String[] args) {
new Bordergrid();
}

/** The buildPanels() method will set the layout and call the individual
methods that build the lift, thrust, the forces of flight, drag, and weight
panel. Then all panels are added to the mainPanel of the JFrame.
*/


public void buildPanels() {
mainpanel.setLayout(new BorderLayout());
buildNorthPanel();
buildSouthPanel();
buildEastPanel();
buildWestPanel();
buildCenterPanel();
mainPanel.setLayout(new BorderLayout());
mainpanel.add(liftLabel, BorderLayout.NORTH);
mainpanel.add(weightLabel, BorderLayout.SOUTH);
mainpanel.add(dragLabel, BorderLayout.EAST);
mainpanel.add(thrustLabel, BorderLayout.WEST);
mainpanel.add(flightLabel, BorderLayout.CENTER);
setVisible(true);
add(mainPanel);
}

/** Build the north panel
*/
public void buildNorthPanel() {
northPanel.setLayout(new GridLayout(2,2));
nouthPanel.add(liftLabel);
}

/** Build the south panel
*/
public void buildSouthPanel() {
southPanel.setLayout(new Gridlayout(2,2));
southPanel.add(weight);
}

/**Build the east panel
*/

public void buildEastPanel() {
eastPanel.setLayout(new GridLayout(2,2));
eastPanel.add(drag);
}

/** Build the west panel
*/

public void buildWestPanel() {
westPanel.setLayout(new GridLayout(2,2));
westPanel.add(thrust);
}

/** Build the center panel
*/
public void buildCenterPanel() {
centerPanel.setLayout(new GridLayout(2,2));
centerPanel.add(flight);
}
}

User is offlineProfile CardPM
+Quote Post

pbl
RE: Help With A Boarder Layout
25 Jun, 2008 - 06:09 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Please your code like this:

code.gif

Make it easier for us:

Many times you spelled "mainPanel" "mainpanel" that generates 6 errors
and you set its layout twice

You spelled once "northPanel" "nouthPanel"
You wrote "Gridlayout" instead of "GridLayout"

You added to panels: "drag", "thrust", "flight" and "drag" which are not defined
they cannot be dragLabel, thrustLabel, flightLabel and dragLabel as you have already added them to mainPanel so who are they ?

I can make typos typing this reply, or you giving a name to this topic, but you can't in a Java program

This post has been edited by pbl: 25 Jun, 2008 - 06:11 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 01:31AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month