It's not a secret anymore!
The moose likes Beginning Java and the fly likes BorderLayout error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "BorderLayout error" Watch "BorderLayout error" New topic

BorderLayout error

Ian Cockcroft

Joined: Feb 17, 2002
Posts: 29
Hi all,
I have put this code into my compiler, it is straight out of a book, exact, word for word and even the API specs say its right, but I get an error.
Does anyone know whats wrong?

The error i'm getting is cannot resolve symbol
symbol : class BorderLayout
location: class SwingUI
panel.setLayout(new BorderLayout
There might be some unclosed string error cause this editor is to small.
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
I don't happen to have a compiler handy, so please tell me if I'm wrong......
I think the problem is with the following import statement:
import java.awt.BorderLayout.*;
This statement essentially tries to import all class files in the package java.awt.BorderLayout. However, BorderLayout is a class that belongs to the package java.awt. Therefore, the import statement as you've listed it does not import the BorderLayout class. Rather, it tries to import all classes of a fictitous package java.awt.BorderLayout.
Try changing your import statement to:
import java.awt.BorderLayout;
[ April 11, 2002: Message edited by: Dave Winn ]

Fun programming etcetera!
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Well, if you fully qualify the classes it will work.
Or you can change your imports to actually import those classes (get rid of the .*)
import java.awt.Color;
import java.awt.BorderLayout;
Or you can just change your import to
import java.awt.*;
//import java.awt.Color.*;
//import java.awt.BorderLayout.*;

PS: you will need to add:
public void actionPerformed(ActionEvent e){//fun stuff};

"JavaRanch, where the deer and the Certified play" - David O'Meara
Ian Cockcroft

Joined: Feb 17, 2002
Posts: 29
Thanks guys, it works fine now.Feel a bit silly. :roll:
I have added the event handler...
I agree. Here's the link:
subject: BorderLayout error
It's not a secret anymore!