john-paul York

Greenhorn
+ Follow
since Feb 15, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by john-paul York

Rob Spoor wrote:A Thread ends when its run() method ends.



am I correct in thinking the run() method is like the start() method? I was trying to figure out when the start menu finishs to print a message out....but can't seem to get it to work....I tried using a variable and then something like this:

if(horseOne.var != horseTwo.var)
{
print a message
}

but that did not work. My thought was if the two variables started the same and when one thread was done it could change its variable an they would be different. This if statement would then kick in and print the message...but as mentioned..that did not work.
13 years ago
I am creating a racing program to practice simple threads and this is what I have so far:






So this is simple enough, it prints out the name of the horse 50 times each randomly as the threads run at the same time. I am now looking to have a message printed out to say which horse won, this is where I run into issues. Is there a way maybe when a thread stops to print a message out? Can someone point me in the right direction?
13 years ago
I am creating a simple tic tac toe game and when I try to add a JButton array to the applet it displays nothing, so I have for now went to displaying the buttons one at a time. My code as it stands now is as follows:



the code I tried to use to add a JButton array was like this(I used something like this for checkboxes in another program):



using the above my applet comes up blank..doing it the way at the top..it shows fine.
13 years ago
bah...I think I have it...JPanel....if I research JPanel this should put be in the right direction I am thinking?
14 years ago
I am doing a program that is suppose to do the following:

Create a JFrame that uses BorderLayout. Place a JButton in the center region. Each time the user clicks the JButton, change the background colour in one of the other regions.

I am just looking for a answer to a quick question, do you have to add buttons into every region to see them? I keep looking for information on how to kind of have a blank region so I can change the background color, but can't find anything(all the examples I find add buttons/text areas)? I am thinking I should be able to add something else other then a button or text area to the other regions that makes those regions show up and then I can work with them.

JP

14 years ago
Thanks guys for the info...as always your friendly and quick

cheers

JP
14 years ago
I am just doing some trial and error right now..really just spit balling some stuff....but I have researched and can't find anything to do what I am looking to do. Right now I have a JFrame created with a bunch of checkboxes and a button. I am trying to just create a simple game where the person who checks the last checkbox wins. I have the box created and have got it to disable any already checked checkboxes. I am thinking that when the button is clicked it would then do some code to randomly check some boxes (computer plays against the human.) I am at the point where I think I need to be able to read the all the JFrames components and then create some if statements to figure out if a)the component is a checkbox and b) if that checkbox is unchecked..check it. I have been trying to use getComponents() with no success. I am just hoping for a nudge in the right direction.

14 years ago
Thanks for the tips...when I load up my work laptop later tonight I will definitly play with the file and try your suggestions...much appreciated.
14 years ago
I am working on a program and am 95% done, but am stuck. My program creates a file and the user can file it with account ID's and balances. The issue I am having is that when a user enters a duplicate account ID it needs to throw an error and I am thinking after the error it should then ask for more ID's. At this point I can enter all the ID's I want and after I enter a duplicate entry it does throw the error, but then the program exits. How do I get it to continue asking for ID's.....any hints?

[edit]Break long lines and change // comments to /* */ to reduce horizontal scrolling CR[/edit]
14 years ago
seems I make progress...need help..make some progress..and need more help....I am getting a nullPointerException for a project I am doing...I want to display all the info in each object that is in each order, so I got it to work if I fill the max number of items out, but if I don't fill the array it throws a nullPointer. I tried using a counter whenever a object was added and then during the display function just looping through with the max being that counter, but that did not seem to work. Any suggestions

14 years ago
I just want to say thanks guys...I went back and reviewed static variables and from what I understand now is that because they where static it was only making one variable and all the objects I was making where accessing the one variable. I say this only because maybe I am still wrong, but once I read that I cleaned up the top of my file and moved the variables to a different spot and it now works

14 years ago

Ralph Cook wrote:It would help if you could point to a line of code or an output that shows your error. Otherwise, to help you, I first have to figure out what you mean by "when the loop is done" and where you're creating this object and what evidence you have that the amount is incorrect.

rc



I have updated the file with some comments on what is going on in the GadetOrderTake file, and below is the output when I try to do the orders...

12.99Quantity is: 1

12.99
7.55Quantity is: 1

20.54
9.99Quantity is: 1

30.53
6.89Quantity is: 1

37.42

Above is the first object and I just have system outs showing the price of the item orders, the quantity and the total price at that time, as you can see I am entering just 1 of the item and the total price is going up fine, but below is where the new object is created (so it asks for a new customer name and address) and then the total price just keeps going up where I would expect instead of 47.41 I would see 9.99

9.99Quantity is: 1

47.410000000000004
14 years ago
I am working on a school assignment and I have run into an issue where I am creating 4 objects and in each object I have to get a total price of all the items in the order. So I create 4 order objects and I fill it with information, one of the items is "final price" and for the first object everything is fine the total keeps going up as needed, but when the loop is done and a new object is created the new object keeps the "final price" value and does not reset back to zero. I thought when a new object was created it would go back to zero and start a new final price value. Can anyone take a look at this file and see if I am doing something wrong (which I am sure I am)



If you want the other files to do this here they are:



14 years ago

fred rosenberger wrote:If you know your array needs to hold four items, I'd declare it as a member variable...


then your constructor would be something like


(note - i'm working on a loaner pc, which does not have the JDK installed, so I can't test/verify my example)

Obviously you'd need to adjust it to pass in the other params, but this might give you a few ideas.



Once again thanks a bunch Fred, while working on it today I have changed my GadgetOrderTaker file to the following:


the reason I came up with this is that now everytime I create a Order object it would then fill it with a item number and matching quantity. I am testing with just one object right now and am working on a good way to automatically create another object that I can then fill again with the same info. Once I am able to create 4 seperate Order objects with upto 4 items with quantity I am thinking I can start to build around them with regards to calculating total price/S&H/etc.

I post this because if you see an issue maybe I might be heading int that would be great....thanks again for the continued input
14 years ago

fred rosenberger wrote:I'm not sure I can answer all your questions, but...

A "list of item numbers ordered (up to four)" to me sounds like you'd want an array of size four. you'll need methods to add or delete items, and to make sure you don't try and add a fifth.

Alternatively, you could just have four integers called something like "orderId1", "orderID2", etc. you could have specific methods for adding or deleting each of the four, plus a method for getting each. Using an array could be simpler, and make your life easier if next week you need to update it to have 8 orders (or 12, or 2000).

My PERSONAL opinion would be you should NOT have a variable holding the price of all items. If you have a list of the items, you should calculate the total when you need it. If you have a variable, you need to do a lot more updating each and every time an item is added or deleted, and you're data can become out of sync if that gets messed up.

Another tip would be to not store prices as floats. you are dooming your code to weird rounding issues. Money should be stored as an atomic unit, which (for the U.S.) is pennies. Then you can re-format it as needed when you want to print/display it.



Thanks for the info Fred, unfortunately I have to have a variable to hold the total price as the project says it needs it. I agree with the array size four for the list, but when I thought of that it made me think of more questions...such as do I create a array of size four in the Order constructor then? that sounded incorrect to me, but the project says "Include a constructor to set the field values" so I am think I need to set the array somehow and for some reason....the array of item numbers would have to be based on input from the user, so how would that work? I am re reading the array, "methods, classes, and objects" chapters as I think they might help me out in this situation....
14 years ago