Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

Rob Petterson

Ranch Hand
+ Follow
since Jan 23, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rob Petterson

For SmartUpload go to this URL
http://www.jspsmart.com/
18 years ago
JSP
Thanks Elouise for unscrambling that for me. I had most of that logic in my brain, all tangled up, but couldn't put it down on paper.
19 years ago
Hi all,
I'm having trouble working out what logic to put into a method called isWarmer().
This is description of what the prog should do:
Write a program that plays �guess the number� as follows: Your program chooses the number to be guessed by selecting an integer at random in the range 1 � 1000.
The program then displays in a label:
I have a number between 0 and 1000 can you guess my number?
Please enter your first guess
A JTextField should be used to input the guess. As each guess is input the background colour should change to either red or blue.
Red indicates that the user is getting �warmer� and blue indicates that the user is getting "colder."
A JLabel should display either "Too High" or "Too Low" to help the user zero in on the correct answer.
When the user gets the correct answer "Correct!" should be displayed and the JTextField used for input should be changed to uneditable.
A JButton should be provided to allow the user to play the game again. When the Button is clicked, a new random number should be generated and
the input JTextField changed to editable.
Here's my rough code:
//import.....
//public class Guess extends JApplet......
{
int guess, randNum;
//generate random number
// user enters a guess
if(guess.isWarmer())
{
//print message saying Getting Warmer
//change the background colour to blue
}
if(!(guess.isWarmer()))
{
//message saying Getting Colder
//change background colour to red
}
else{
//print Correct Answer
//set textField to uneditable
playAgain();
}
public boolean isWarmer()
{
//not sure what to put here??
}
//playAgain() method defined here.
}
Any ideas,

Rob
19 years ago
Hi,
Can anyone tell me what method I need to use for outputting results into a JTextField?
Say for example in the case of adding 2 numbers together and wanting to display the result in a JTextField???
19 years ago
Abhilash,
Iv'e done as you said and moved the assignments to here:

So, I now get the GUI displaying propery. I can enter 2 numbers into the textfields and click on a radio button such as'+' to add the 2 numbers together. I then click the 'calculate' button but nothing appears in the result textfield.
Is there something wrong in the if statements to do with setText()???
19 years ago
Can anyone tell me why I'm getting a NumberFormatException, coz for the life of me I can't see whats wrong with it.
It's basically an applet that allows you to enter 2 numbers which when you click on 1 of 4 radio buttons( +, -, *, / ) and then click calculate, displays the answer in a JTextField. I've used the method getText() to retrieve the inputted strings, then converted these to ints, did the calculation, then converted them back to a String in order to display in the result JTextField.(Is it possible to leave the result as an int to display in result field?)

Any help would really be appreciated
19 years ago
OK, I've just had a flash on insight.
This will sort it out now:

Irene, thankyou for all your help on this. Very much appreciated.

Rob
[ May 08, 2003: Message edited by: Rob Petterson ]
Evening Irene,
I've got it to work! Yee Haa!
I've included the code here to show you what I've added.
I had to convert the first 4 params from strings to ints and floats. Secondly I deleted the single quotes from around these variables.
Thirdly, I hadn't set the field length in the 'keyword' field in the original jsp form, so I was getting a value of null which was giving a NullPointerException.
Everything works now EXCEPT one little thing. You'll notice when reading the code that if you don't give a 'lowYear' value, any other vals that you give will start with AND in the sql query I.e. this:
SELECT * FROM Coin WHERE AND Country = 'English'

ps
I've really got to get into the habbit of using s.o.p's throughout my code to what vals variables have been given.

Rob

[ May 07, 2003: Message edited by: Rob Petterson ]
thanks Jenny for you input, that AND AND was just a typo from me and not in the code.
Thanks Irene. I try this out tonight.
Rob
Hi Irene,
This is strange. I'm still getting the same SQL error appearing in my application - even after cut and pasting in your corrected code.
I've opened up a Dos screen and navigated to where my DB is and manually typed in a scenario using the code within the if statements eg:
SELECT * FROM Coin WHERE Year > 1200 AND Year <1980 AND AND Product_Price <1500;
It works and gives me all records that match that criteria.
So once again I'm stumped.

Rob

[ May 06, 2003: Message edited by: Rob Petterson ]
Hi Irene,
I'm getting an error message regarding the syntax of the SQL statements. I've been playing around with it, changing things around but can't get it to work.
If I enter say, 500 in the hightYear field and Charles II in the Keywords field, this is the error message I get:
org.apache.jasper.JasperException: Syntax error or access violation, message from server: "You have an error in your SQL syntax near 'AND Product_Price < '500AND Product_Full_Desc LIKE '%Charles IIAND Country = 'En' at line 1"

Also, I want to be able to put a % on each side of the keyword and suffix variable as well.
I've just realized that I have to put an 'All Coin Type' as the default for the Coin Type drop-down menu field within the form (Obviously all the other types are listed underneath).
I thought maybe that I could put this into the if statement something like:
if (type.equals("All Coin Types"))
{
strBuffer.append("AND Type =//not sure what to put here in order to list all the coins for that country (there's a Country field next to the Coin Type field)
}
Here's the code:

Thanks, Rob
[ May 05, 2003: Message edited by: Rob Petterson ]
Thanks Irene,
I will try this out in the morning and will let you know how I get on.
Cheers, Rob
Thanks Irene.
I understand what you're saying about making it a bit more sophisticated by adding conditional statements. I have been for some time (days) now been trying to work out how to do this but have only managed to come up with the method I posted. It's pretty rough I know.
Would it be asking too much for you to get me started with how to code this properly?
Rob.