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 / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

Have a constructer with the paramters sent through an applet store them as global variables

Thread view: 
Richard Perreault - 24 Mar 2006 00:48 GMT
I have a program that uses an applet to transfer parameters from an Html
page. And transfer them to a constructor. This works very well, I did add
println commands to make sure it functions properly. When I open the applet
which loads a frame. I see the variables even before the frame is loaded. My
problem is that these variables are not global. If I do not create the
variable at the beginning of the Frame I get an error as symbol not found.
Here is some snippets of my program.

This is the applet
               Url = getParameter("Url");
               HTTP = getParameter("HTTP");
               System.out.println(Url);
               System.out.println(HTTP);

               //try {
               //finalapp being loaded
               //This is how you pass parameters from an applet to a frame!
               window = new finalapp (Url,HTTP,"Pop-Up Window");
               //catch (IOException e) {
               //System.out.println("Error: "+ e.getMessage());
               //}

And this is the constructor of the Frame

// Constructor
public finalapp(String Url,String HTTP,String title)
{
       super(title);
       System.out.println(Url+" "+HTTP);
       // Read the Questions file;
       // Frame Initialization

Can anyone please tell me how to make the Url and HTTP global variables in
the Frame.
Nigel Wade - 24 Mar 2006 11:22 GMT
> I have a program that uses an applet to transfer parameters from an Html
> page. And transfer them to a constructor. This works very well, I did add
[quoted text clipped - 6 lines]
> This is the applet
>                 Url = getParameter("Url");

It would help enormously if you adhered to the convention that variable names
begin with a lowercase letter and class names with uppercase. When I first saw
the above line I thought it was totally incorrect because you were attempting
to assign a String to a Url.

In newsgroups communication is everything, and failing to communicate
successfully means that you won't get the help you want. Making our life easier
by using the conventions is more likely to get help, rather than being ignored.

>                 HTTP = getParameter("HTTP");
>                 System.out.println(Url);
[quoted text clipped - 20 lines]
> Can anyone please tell me how to make the Url and HTTP global variables in
> the Frame.

A variable which is "global" to a class is a class variable (static) in that it
is shared amongst all instances of that class. But I don't think that's what
you want here. I think what you want is a variable which is accessible by all
methods within the class. For that you want an instance variable. These are
defined in the class, but outside of any method. They can be set within the
constructor.

You can't make a variable which is a parameter to the constructor visible to
other methods, you have to declare a variable in the scope of the class and set
it in the constructor.

e.g.

public class FinalApp {
 String url;
 String http;

 public FinalApp(String Url,String HTTP,String title) {
   ...
   url = Url;
   http = HTTP;
   ...
 }

 public void someMethod() {
   System.out.println(url);
 }
...

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Richard Perreault - 25 Mar 2006 00:04 GMT
Thank you that work perfectly.

>> I have a program that uses an applet to transfer parameters from an Html
>> page. And transfer them to a constructor. This works very well, I did add
[quoted text clipped - 86 lines]
>  }
> ...


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



©2008 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.