Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

borderlayout on a frame

  Asked By: Rufus    Date: Apr 21    Category: Java    Views: 755

I wanted to do a borderlayout on a frame and add a couple of panels
to put buttons on. I came up with this code:
import java.awt.*;
import java.awt.event.*;
Panel panel1;

class borderFrame extends Frame{
public borderFrame(){
super("This is a frame");
setLayout(new BorderLayout());
public panel1(){
Panel panel1=new Panel();
panel1.add( new button1, "WEST");
class terminate extends WindowAdapter implements WindowListener{
public void windowClosing(WindowEvent e){
Is this code correct for a frame with a borderLayout and a panel in
the west portion of the frame?



1 Answer Found

Answer #1    Answered By: Julia Flores     Answered On: Apr 21

First, I don't understand the panel  panel1 declaration outside the
Second, why use
public panel1()?

You don't have a void return value.
Change it to public void panel1().

Don't put  numbers in you variable names.
Don't create to objects with same name in the same class.
If you don't need the objects outside the class, declare them
private. Layout objects, such as Panels, should be placed
outside a method, because it's easier to use them later from
other methods.

Then don't extend WindowAdapter and implement
WindowListener at the same time! When implementing
WindowListener, you must override all the methods in the
WindowListener interface. When extending WindowAdapter, you
don't need to override all the methods. That's the difference
between extending and implementing. You write an interface
when passing unknown objects to a function. WindowAdapter is
implementing WindowListener.

If you want to extend a Frame, you must put a
public void main(String args[ ])
The create an instance of your class, or you will never see you
window! (if you not use it from another class)

Didn't find what you were looking for? Find more on borderlayout on a frame Or get search suggestion and latest updates.