Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

NetBeans and argument of constructor

Thread view: 
Mariano - 20 Jul 2007 04:05 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
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.