wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Class Container not found :( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Class Container not found :( " Watch "Class Container not found :( " New topic
Author

Class Container not found :(

Renu Mahesh
Greenhorn

Joined: Sep 14, 2004
Posts: 2
Hi,
I am new to swing. Trying to learn. I am trying to write some code to add a few labels, text fields and a button and add them to the JFrame. When I am setting the layout to Gridlayout and trying to compile, I am getting an error message "Class Container not found". can somebody help me?
Thanks
Renu
Bernhard Jung
Greenhorn

Joined: Sep 14, 2004
Posts: 11
read this:
http://java.sun.com/docs/books/tutorial/uiswing/index.html

this:
import java.awt.*;
import javax.swing.*;

or post some code please.
[ September 15, 2004: Message edited by: Nargaff ]
Renu Mahesh
Greenhorn

Joined: Sep 14, 2004
Posts: 2
The code is



import javax.swing.*;
import java.awt.*;
public class SampleCode extends JFrame{
JLabel name = new JLabel("Name");
JLabel occupation = new JLabel("occupation");
JButton submit = new JButton ("Submit");
JTextField txt_name = new JTextField(25);
JTextField txt_Occupation = new JTextField(35);
public static void main(String args[]){
SampleCode sc = new SampleCode();
Container cont = sc.getContentPane();
cont.setLayout(new GridLayout(2,2));
cont.add(name);
cont.add(occupation);
cont.add(txt_name);
cont.add(txt_occupation);
cont.add(submit);
sc.pack();
sc.setVisible(true);
}

}
Bernhard Jung
Greenhorn

Joined: Sep 14, 2004
Posts: 11
I don't get the 'Class Container not found' message, but check your Classpath if you still get it.
http://faq.javaranch.com/view?HowToSetTheClasspath

Trying to compile i get this:
non-static variable name cannot be referenced from a static context
cont.add(name);

You have to understand what's the difference between a class, an object/instance, a static field and a instance field.
http://faq.javaranch.com/view?JavaBeginnersFaq
and I recommend reading chapter 1+2 of 'Thinking in Java'.
http://mindview.net/Books
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Nargaff,

Welcome to JavaRanch!

You may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Initials aren't enough. You can change your display name here.
Thanks, pardner, and hope to see you around the Ranch!


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class Container not found :(