Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Passing values to constructor

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will post all code in a follow on. In the interest of space, I have only
posted portions here. I am trying to pass values from one class if the
button is pressed to another class' constructor. I am clearly not doing
this correctly.

Thanks for your help.


_______________________________________


I'll post both class files below but hopefully this text is enough to
figure out what is wrong.

Thanks!
[ May 24, 2005: Message edited by: Gregg Bolinger ]
 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is all of the code in both classes.


Here is the second class


[Gregg Bolinger - Edited to fix page width problems.]
[ May 24, 2005: Message edited by: Gregg Bolinger ]
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method you are using to pass values to the constructor is fine.

What problems are you experiencing? Are you using the passed in values correctly? Why is your userID and password null?

Maybe you need to do:
String userID = uNameString ;
String password = pWordString ;
 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fahd,

The userID and password are "null" because they are not required to
log into the DB. The reason for passing the values is for use in the
query "SELECT FirstName, LastName FROM CUS_USER (the table)
WHERE EmailAddress = 'uNameString' (first string) AND Pasword =
'pWordString'(the second string)";

But, when I compile, I get the following error:
"TestMainScreen.java:67: cannot find symbol
symbol: constructor TestLogin(java.lang.String,java.lang.String)
location: class TestLogin
TestLogin tl = new TestLogin(uNameString, pWordString);
^
1 error
 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The carrot in the preceding should be under new BTW.
 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fixed it by playing around... here is how:

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some questins and comments.

Why is there a main method in your TestLogin class and why does it extend JFrame?

String uNameString = "null";
String pWordString = "null";

That does not set those variables to null. That sets those variables to a string value that equals a literal string null. You probably meant to do:

String uNameString = null;
String pWordString = null;

Let's look at what you are trying to do but much simpler.



 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg,

The simple answer is: I don't know... I just kept trying things until
it worked. Not very scientific to be sure.

I extended JFrame in that class only to create a new screen. I am sure
that is not the right way to go about it which is why I have found
this forum to be so very valuable. I have gotten more to work in the
last four days due to you and Ernest's help than I have ever understood
in the past. Please keep the comments coming. What I generally do is
get the thing to just work. That is all I care about. After I do that,
I try some other things (play with the code and see what breaks it and
what makes it work with less code). For instance, I did not even try
to pass these values and create a new object until I got both classes
working all by themselves. Once I tried that, it broke. Then I tried a
whole bunch of things until it worked again. Once you give me feedback,
I make leeps and bounds. It is funny that so many of the things that I am
told after I try the dumb way just seems so obvious later on. This forum
has been outstanding for helping me learn.


 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I gotta ask ... do you get a lot of "Al wells that end wells" ??
 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All through my childhood and still to this day. What is worse is that my
name is short for Alvin. My parents were high when I was born. I wonder if
it is too late to switch to using my middle name...

 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Al Wells:
The carrot in the preceding should be under new BTW.



That typo made my day, I'm still grinning - thanks!

If you want to preserve the formatting of your text, for example for positioning carets, you need to use code tags.
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic