Brian Pianczk

Ranch Hand
+ Follow
since Jan 26, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Brian Pianczk

Make sure you let everyone know about the cross threads.

http://forums.sun.com/thread.jspa?threadID=5375236&tstart=15

15 years ago

David Ausman wrote:Well, now I feel dumb. In my own defense that download button looks like it is associated with the item above it. I kept clicking on the "docs" button because that is associated with the correct item.

Thanks very much!



I had that same problem.
15 years ago

Campbell Ritchie wrote:If it is a private static field in the Card class, how can you access it from the Deck class?



Oops

15 years ago
But you haven't actually changed the functionality of the code? It is still taking Player.number and creating a random number in the Player.guess method. It doesn't matter if the instance variable is public and you use a void method, or the instance variable is private and you use a return method. You still get the same result, just your second example protects the instance variable.

I went through this chapter last week, and didn't experience your initial problem.
15 years ago
Thanks to both of you. I understand now, and yes the Card class contains a private static variable for each suit, and rank.

15 years ago



Having just gone through the section on Arrays, again is this how this bit of code is working?



does this loop first make the DIAMONDS column then add the 13 cards to it, then create SPADES then add cards etc...?

15 years ago

amitabh mehra wrote:
the try-catch I suggested was never meant as an "exit" route. It was for that "dirty" exception stack trace which you would not want the user to see.
For exit purpose, perhaps you can prompt the user to enter something like 'quit' and change your code a bit in the way like:


Now this will still give "Not a number" message to user in case non-number is entered and allow the user to continue. else 'quit' the application.



Thanks, I am trying to learn java, and all these suggestions help. It is amazing how many solutions there are to one problem, and each one I learn something new.
15 years ago

Jeanne Boyarsky wrote:Brian,
How about using a boolean?



Still thinking about how I can apply this. Are you saying make the whole method a boolean?
15 years ago

amitabh mehra wrote:or use a try-catch block:



Thanks for the quick responses!

I like this idea, but I am guessing it would be bad programming to use an exception to exit a program?

Like if I were to say "Enter an integer, or just return to exit: " then use the exception to exit? and display "goodbye" in the exception.


Edit: never mind this idea, doesn't solve the issue if someone enters a non integer.


15 years ago
Hi all, I am trying to figure out a way to exit this do-while. I am wondering how it can be done w/out using a number.
I originally did it with a while num > 0 and used an int num variable, but a neg number can be even or odd.
My new approach gives me an error (unknown source) when it reads a blank entry.





Error when I just use a space or enter.
c:\Program Files\Java>java Test
Enter an integer:
Exception in thread "main" java.lang.NumberFormatException: For input string: ""

at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Test.getNum(Test.java:17)
at Test.main(Test.java:7)

c:\Program Files\Java>
15 years ago
Thank you! I looked over this code again and again. Even line by line and did not notice. Even when I pinpointed it to that bit of code.

Thanks again!
15 years ago
OK I have two sets of code here both, to me, look to be the same except for style differences. One I wrote from doing the section in the book MiniMusicPlayer. The other was a direct copy and paste MiniMusicPlayer3.
Mine doesn't work, it plays the track, but doesn't display the random rectangles. The copied and pasted code works.
I can't recognize the difference in the two codes,(myDrawPanel is named different in the two, but referenced the same way) I am curious if anyone else can see something I am not seeing?


Mine


Copied version

15 years ago
Hi all, is there any way to return a method's origin?

Besides typing in toCharArray in a Google search box; is there a way to display where a method is located, using Java?

Like a getClass() ?

Edit: Just using toCharArray as an example, I don't want to know that method specifically. I know it is in java.lang.String.
15 years ago
I appreciate the patience, thanks to both of you. I now understand what exactly is going on.
15 years ago

Maneesh Godbole wrote:Whenever you stretch, resize, move the window, the JVM repaints it. And guess where your to paint the circle sits? In the paint method!

Though the paint is the correct place to have the circle code, if you want a consistent color, irrespective of what you do, just move your color generation code outside paint. Every time the paint is called, your code comes up with a new color.



Ok if I understand corectly , my problem is in :


Before I go into the errors I have found trying to minipulate that class, could we confirm this is the source of my "trouble"?

Thanks

I am assuming by when you say paint, you are referring to lines 16 and 17?
15 years ago