I've this class, Gestisci.java, when I initialize this class from
Crea.java class I need to pass an argument to the constructor so code
in class Crea.java will be something like that:
new Gestisci(myStringVariable).setVisible(true)
=======================================
//File: Gestisci.java
public class Gestisci extends javax.swing.JFrame {
private String tipo; // declare tipo
public Gestisci(String t) { // accept string
this.tipo = t; // "bind"
}
// START A METHOD
System.out.println(tipo);
// END METHOD
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Gestisci(???).setVisible(true); // AND HERE???
}
});
}
=======================================
Now my knowledge stop here, but, what I've to put in main at place of
'???' to correctly compile?
Lew - 20 Jul 2007 13:19 GMT
> I've this class, Gestisci.java, when I initialize this class from
> Crea.java class I need to pass an argument to the constructor so code
[quoted text clipped - 12 lines]
> // START A METHOD
> System.out.println(tipo);
This line will not compile. Statements need to be inside initializer blocks,
constructors or methods, not dangling "loose" as this one is.
> // END METHOD
>
[quoted text clipped - 10 lines]
> Now my knowledge stop here, but, what I've to put in main at place of
> '???' to correctly compile?
Whatever String you wish the Gestisci class to hold in its 'tipo' member.
What does the logic of your problem (that you are trying to solve) dictate?
In other words, what is the information that you want the Gestisci instance to
remember?

Signature
Lew
Eric Sosman - 20 Jul 2007 14:02 GMT
> I've this class, Gestisci.java, when I initialize this class from
> Crea.java class I need to pass an argument to the constructor so code
[quoted text clipped - 26 lines]
> Now my knowledge stop here, but, what I've to put in main at place of
> '???' to correctly compile?
A String (or null). The value you supply in main will
be known as `t' in the Gestisci constructor, and will become
the initial value of `tipo' in the new Gestisci object.

Signature
Eric Sosman
esosman@ieee-dot-org.invalid
Mark Space - 20 Jul 2007 20:01 GMT
> I've this class, Gestisci.java, when I initialize this class from
> Crea.java class I need to pass an argument to the constructor so code
[quoted text clipped - 9 lines]
> public Gestisci(String t) { // accept string
> this.tipo = t; // "bind"
> System.out.println(tipo); // MUST BE INSIDE A METHOD
> } // CHANGED THIS
> public static void main(String args[]) {
[quoted text clipped - 9 lines]
> Now my knowledge stop here, but, what I've to put in main at place of
> '???' to correctly compile?
I made some changes above. Please see the changed code.