Hello Dear Brothers and sisters
How are you................?

I'm Student of bscs in 6th semester
i write three programs but all of these are giving errors and i'm not able to findout probelm. but i thing problem is some where with CONTAINER
please check all these

Thanks

First One

import javax.swing.*;
public class FlowLayout{
  JFrame myFrame;
  JButton b1, b2, b3, b4, b5;


  //method used for setting layout of GUI
  public void initGUI(){
    myFrame = new JFrame("Flow Layout");
    Container c = myFrame.getContentPane();
    c.setLayout(new FlowLayout());

    b1 = new JButton("Next Button");
    b2 = new JButton("Previous Button");
    b3 = new JButton("Back Button");
    b4 = new JButton("Last Button");
    b5 = new JButton("Exit");

     c.add(b1);
     c.add(b2);
     c.add(b3);
     c.add(b4);
     c.add(b5);
     
     myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     myFrame.setSize(100, 150);
     myFrame.setVisible(true);
  }//end initGui method

  public FlowLayoutTest(){//defualt constructor
      initGUI();
  }
  public static void main (String[] args){
    FlowLayoutTest TestOne = new FlowLayoutTest();
  }
}

Second One

//import java.awt.*;
import javax.swing.*;
public class GUITest{
  JFrame myFrame;
  JTextField tf;
  JButton b;


//method use for setting layout of GUI
public void initGUI(){
  //step 2: setup the top level container
  myFrame = new JFrame();

  //Setup 3: Get the component area of the top-level container
  Conntainer c = myFrame.getContentPane();

  //Setup 4: Apply layout
  c.setLayout(new FlowLayout());

  //Setup 5: create & add components
  JTextField tf = new JTextField(10);
  JButton b1 = new JButton ("My Button");
  c.add(tf);
  c.add(b);
  
  //Setup 6: set size of frame and make it visible
  myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  myFrame.setSize(200, 150);
  myFrame.setVisible(true);
}
  //end initGUI METHOD
public GUITest(){   //default constructor
  initGUI();
}
public static void main (String args[]){
  GUITest gui  = new GUITest();
}
}

Third One

import java.awt.*;
import javax.swing.*;
public class GridLayoutTest{
  JFrame myFrame;
  JButton b1, b2, b3, b4, b5;
  //method used for setting layout of GUI
  public void initGUI(){
    myFrame = new JFrame("Grid Layout");
    Container c = myFrame.getContenPane();

    c.setLayout(new GridLayout(3, 2));
    b1 = new JButton ("Next Slide");
    b2 = new JButton ("Previous Slide");
    b3 = new JButton ("Back to Start");
    b4 = new JButton ("Last Slide");
    b5 = new JButton ("Exit");

    c.add(b1);
    c.add(b2);
    c.add(b3);
    c.add(b4);
    c.add(b5);
    
    myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    myFrame.setSize(300, 150);
    myFrame.setVisible(true);
  }
  
  public GridLayoutTest(){
    initGUI();
  }
  
  public static void mian (String args[]){
    GridLayoutTest glTest = new GridLayoutTest();
  }

}

all of these are giving errors and i'm not able to findout probelm.

You need to post the full text of the error messages. Without them it is hard to tell you what the problem is.

You need to post the full text of the error messages. Without them it is hard to tell you what the problem is.

Hello Dear Brother Please check screenshot For Output of command prompt.

Attachments one.JPG 76.27 KB

To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

Images are hard to work with because you can not copy and paste text displayed in the image.

The first error looks like you have a method that is coded like it is a constructor. It needs to have a return type. Or have you misnamed the class?

Edited 5 Years Ago by NormR1: n/a

Now please check output.

D:\javac>cd d:\javac\10lec


D:\javac\10lec>dir
Volume in drive D has no label.
Volume Serial Number is C0A0-F38F


Directory of D:\javac\10lec


11/05/2011  10:38 PM    <DIR>          .
11/05/2011  10:38 PM    <DIR>          ..
11/05/2011  10:37 PM               906 FlowLayout.java
11/05/2011  10:50 PM               888 GridLayoutTest.java
11/05/2011  08:41 PM               919 GUITest.java
3 File(s)          2,713 bytes
2 Dir(s)   1,533,267,968 bytes free


D:\javac\10lec>javac FlowLayout.java
FlowLayout.java:30: error: invalid method declaration; return type required
public FlowLayoutTest(){//defualt constructor
^
1 error


D:\javac\10lec>javac GridLayoutTest.java
GridLayoutTest.java:9: error: cannot find symbol
Container c = myFrame.getContenPane();
^
symbol:   method getContenPane()
location: variable myFrame of type JFrame
1 error


D:\javac\10lec>javac GUITest.java
GUITest.java:15: error: cannot find symbol
Conntainer c = myFrame.getContentPane();
^
symbol:   class Conntainer
location: class GUITest
.\FlowLayout.java:30: error: invalid method declaration; return type required
public FlowLayoutTest(){//defualt constructor
^
.\FlowLayout.java:10: error: cannot find symbol
Container c = myFrame.getContentPane();
^
symbol:   class Container
location: class FlowLayout
.\FlowLayout.java:34: error: cannot find symbol
FlowLayoutTest TestOne = new FlowLayoutTest();
^
symbol:   class FlowLayoutTest
location: class FlowLayout
.\FlowLayout.java:34: error: cannot find symbol
FlowLayoutTest TestOne = new FlowLayoutTest();
^
symbol:   class FlowLayoutTest
location: class FlowLayout
5 errors


D:\javac\10lec>

Edited 3 Years Ago by Nick Evan: Fixed formatting

D:\javac\10lec>javac FlowLayout.java
FlowLayout.java:30: error: invalid method declaration; return type required
public FlowLayoutTest(){//defualt constructor
^
1 error



D:\javac\10lec>javac GridLayoutTest.java
GridLayoutTest.java:9: error: cannot find symbol
Container c = myFrame.getContenPane();
^
symbol:   method getContenPane()
location: variable myFrame of type JFrame
1 error


D:\javac\10lec>javac GUITest.java
GUITest.java:15: error: cannot find symbol
Conntainer c = myFrame.getContentPane();
^
symbol:   class Conntainer
location: class GUITest
.\FlowLayout.java:30: error: invalid method declaration; return type required
public FlowLayoutTest(){//defualt constructor
^
.\FlowLayout.java:10: error: cannot find symbol
Container c = myFrame.getContentPane();
^
symbol:   class Container
location: class FlowLayout
.\FlowLayout.java:34: error: cannot find symbol
FlowLayoutTest TestOne = new FlowLayoutTest();
^
symbol:   class FlowLayoutTest
location: class FlowLayout
.\FlowLayout.java:34: error: cannot find symbol
FlowLayoutTest TestOne = new FlowLayoutTest();
^
symbol:   class FlowLayoutTest
location: class FlowLayout
5 errors

Edited 3 Years Ago by Nick Evan: Fixed formatting

Do you understand what the "cannot find symbol" error means?
The compiler can not find a definition for the symbol shown in the error message.

There are many ways to get this error:
You misspelled a variable or method name
You left out a definition
You did not import the package with that contains a definition for that symbol

Go over each error message and see why the compiler can not find the symbol.
Check your spelling and definitions.

Edited 5 Years Ago by NormR1: n/a

i have tried hard.
but was not able to find out reason of these few errors
first there were so much error. i removed many but rest of them are not possible for me. as i m new student of this programming language.
please read code and try to help me thanks

Ok we'll do them one at a time.

D:\javac\10lec>javac FlowLayout.java
FlowLayout.java:30: error: invalid method declaration; return type required
public FlowLayoutTest(){//defualt constructor

The compiler says this method definition is missing a return type.
Is it a method definition or is it a constructor call and the class name is wrong?
The comment says it is a constructor.

Edited 5 Years Ago by NormR1: n/a

GridLayoutTest.java:9: error: cannot find symbol
Container c = myFrame.getContenPane();
^
symbol: method getContenPane()
location: variable myFrame of type JFrame

Where is the method getContenPane() defined?

Ok we'll do them one at a time.

The compiler says this method definition is missing a return type.
Is it a method definition or is it a constructor call and the class name is wrong?
The comment says it is a constructor.

now i am getting only one error

D:\javac\10lec>javac FlowLayout.java
FlowLayout.java:10: error: cannot find symbol
    Container c = myFrame.getContentPane();
    ^
  symbol:   class Container
  location: class FlowLayout
1 error

and Container error is in all three programs

On final stage how to solve this problem

D:\javac\10lec>javac FlowLayout.java
FlowLayout.java:12: error: method setLayout in class Container cannot be applied
 to given types;
    c.setLayout( new FlowLayout());
     ^
  required: LayoutManager
  found: FlowLayout
  reason: actual argument FlowLayout cannot be converted to LayoutManager by met
hod invocation conversion
1 error

The compiler can not find a definition for the Container class.
Do you have an import statement for the package containing the Container class?

actual argument FlowLayout cannot be converted to LayoutManager by method invocation conversion

What is the definition of the FlowLayout class? The compiler wants a class that extends the LayoutManager class as an argument for the setLayout() method. The FlowLayout class you use does NOT extend the LayoutManager class.

Check the name of YOUR class. You should not be giving it the same name as one of Java's classes. Rename your class.

Edited 5 Years Ago by NormR1: n/a

please tell me one thing
can we use JFrame in container ?
or we have to use JPanel for JFrame?????

A JFrame is for an independent window.
Why would you want it in a container?
Use a JPanel to hold components for GUI that you want to add to a container.

This article has been dead for over six months. Start a new discussion instead.