Wrox Programmer Forums
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 16th, 2006, 06:13 AM
Authorized User
 
Join Date: Jul 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ironchef
Default Layout Managers

I've just started to work with windows and every time i try to add simple buttons using a layout manager(so far i have only flow and border layout), I keep getting the same error massages. I'm using the code below for my border layout and the error massages:

import javax.swing.JFrame;
import javax.swing.JButton;

import javax.swing.border.EtchedBorder;

import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.Container;
import java.awt.BorderLayout;

public class BorderLayout {
 //window object
 static JFrame aWindow = new JFrame("Border Layout");

 public static void main(String[] args) {
  Toolkit theKit = aWindow.getToolkit();
  Dimension wndSize = theKit.getScreenSize();

  //set position to screen center & size to half screen size
  aWindow.setBounds(wndSize.width/4, wndSize.height/4, //position
            wndSize.width/2, wndSize.height/2); //size
  aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CL OSE);

  BorderLayout border = new BorderLayout();
  Container content = aWindow.getContentPane();
  content.setLayout(new BorderLayout());
  EtchedBorder edge = new EtchedBorder(EtchedBorder.RAISED);
  //add 5 JButtons and set their borders
  JButton button;
  content.add(button = new JButton("EAST"), BorderLayout.EAST);
  button.setBorder(edge);
  content.add(button = new JButton("WEST"), BorderLayout.WEST);
  button.setBorder(edge);
  content.add(button = new JButton("NORTH"), BorderLayout.NORTH);
  button.setBorder(edge);
  content.add(button = new JButton("SOUTH"), BorderLayout.SOUTH);
  button.setBorder(edge);
  content.add(button = new JButton("CENTER"), BorderLayout.CENTER);
  button.setBorder(edge);

  aWindow.setVisible(true);
 }
}


error messages:

BorderLayout.java:9: BorderLayout is already defined in this compilation unit
import java.awt.BorderLayout;
^
BorderLayout.java:25: setLayout(java.awt.LayoutManager) in java.awt.Container cannot be applied to (BorderLayout)
content.setLayout(border);
          ^

others that dont matter as much.....





IronChef - http://www.freewebs.com/cool_recipes
__________________
<b>IronChef</b> - http://www.freewebs.com/cool_recipes
 
Old October 20th, 2006, 05:09 AM
Authorized User
 
Join Date: Oct 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, IronChef!
the problem is that the class you have written has the same name with the one you import.
you named your class "BorderLayout" and also imported the class with the same name

(java.awt.BorderLayout).
I guess the compiler mixes that things
I can suggest you to change the name of your class to something like "Borders".
I did it on my machine and that worked well for me.
Cheers,
Ann





Similar Threads
Thread Thread Starter Forum Replies Last Post
3 column layout acevision7 BOOK: Professional CSS: Cascading Style Sheets for Web Design 0 February 24th, 2008 11:13 PM
3 Row Layout simrud CSS Cascading Style Sheets 3 August 1st, 2005 06:47 PM
Datalist layout silverfox_1188 ASP.NET 1.0 and 1.1 Professional 2 May 13th, 2005 05:43 AM
datalist layout silverfox_1188 Classic ASP Components 0 May 11th, 2005 04:16 PM
layout adflynn Java GUI 0 November 9th, 2004 06:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.