class instance
I created a class instance, but something is wrong when I try to run the JFrame?
public Class1 extends JFrame {
Class2 c2;
public Class1(Class2 c2); {
this.c2 = c2;
<stuff>
}
public void main (Strings[] args) {
//what is wrong with the next line?
// slowly please, I am a newbie :-)
Class1 c1 = new Class1(c2);
<stuff>
c1.setVisible(true);
}
}
[449 byte] By [
kiekeboea] at [2007-11-26 23:58:08]

In your main method, you cannot use the c2 variable. If you want a "slow" explanation, read this tutorial:Understanding Instance and Class Members http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html
I know I can't use c2 (obviously :-) ), but the question is, what do I have to use. I tried several things, but not the right thing. Who can give me a hint?
> I know I can't use c2 (obviously :-) ), but the> question is, what do I have to use. A new instance of Class2 (obviously ; ) ).> I tried several things, but not the right thing. What did you try?> Who can give me a hint?I did.
an new instance, obviously indeed :-)
so now I have:
public Class1 extends JFrame {
Class2 c2, cc2;
public Class1(Class2 c2); {
this.c2 = c2;
<stuff>
}
public void main (Strings[] args, Class2 cc2) {
//what is wrong with the next line?
this.cc2 =cc2;
Class1 c1 = new Class1(cc2);
<stuff>
c1.setVisible(true);
}
}
> an new instance, obviously indeed :-)
> so now I have:
> public Class1 extends JFrame {
> Class2 c2, cc2;
> public Class1(Class2 c2); {
> this.c2 = c2;
> <stuff>
> }
> public void main (Strings[] args, Class2 cc2) {
> //what is wrong with the next line?
> this.cc2 =cc2;
> Class1 c1 = new Class1(cc2);
> <stuff>
> c1.setVisible(true);
> }
> }
No, that's not what I meant.
I truly cannot begin to describe what's wrong with that code (there's that much wrong with it). Although this is a "New To Java" forum, you should really start with some basic tutorials, since you do not understand the very basics of the language:
Learning the Java Language:
http://java.sun.com/docs/books/tutorial/java/index.html
this is , obviously, of no help:-(
Vector v = new Vector();v is an instance of Vector.
rym82a at 2007-7-11 15:45:38 >

> this is , obviously, of no help:-(
Yes it is. If you don't know the basic terminology, you'll never learn it.
What would be of help then? Just posting that code, but then corrected by me? Would you really learn from it? No, because the next thing you'll program, you still know jack about Java and the answers given to you.
> this is , obviously, of no help:-(
Ok, here's my help:
> public Class1 extends JFrame {
You need to declare it as a class, and import the JFrame class from the javax.swing package.
> Class2 c2;
You need to declare a Class2 class.
> public Class1(Class2 c2); {
>this.c2 = c2;
>
>}
What is that semi colon doing at the end of your constructor?
>public void main (Strings[] args) {
>//what is wrong with the next line?
>//slowly please, I am a newbie :-)
>Class1 c1 = new Class1(c2);
>
>c1.setVisible(true);
>}
>}
You did not declare a Strings class, nor is it available in the standard Java classes.
If you fix all this, you will still not be able to run this since your main method is not static. By making it static, you will encounter even more problems since you cannot use the variable c2 inside the main method then (see the first link I posted).
There, you got your answers.