Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class Container not found :(

 
Renu Mahesh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic