Fred Kleinschmidt

+ Follow
since Oct 13, 2015
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Fred Kleinschmidt

Also, you have inverted the order of arguments ot the add() method:
1 day ago
And why do you initialize counter to one, when nothing has been entered yet? At the end of the first trip through the loop, when you have entered one number, your value of counter will be two.
1 day ago
There are numerous problems with this coed.
Firs, if you are using Swing, you should not extend Frame, but rather JFrame.

Second, it is usually frowned upon for your program to extend JFrame, either.
It would be better to extend JPanel and have your main() method create a JFrame and put your panel in that JFrame.

Third, the first line of your paintComponent() method should be .
Fourth, you do not have a main() method.
Fifth, all of the GUI code should be executed on the EventThread, not the main thread.

You should start with something much simpler than this. For example, just write something that displays "Hello" in a JLabel that is displayed in your JFrame.
Once you get that to work, then you can go on to show your panel with its buttons, etc.
When you get that to work, then you can go on to add the listeners and get that part to work, too.
1 day ago
Do not call window.pack() until after you have finished creating the entire GUI.
Calling pack causes the JFrame to ask its children what size they prefer to be so it can determine how lay everything out properly.
You are calling pack() immediately after creating the JFrame, before you have added any children to it. Since id has no children yet,  it will decide that its best size is zero by zero.

And if you call pack() just after adding the jPanel to it, the same thing will occur, since you have not yet added anything to the jPanel.

Also, you are calling window.setSize() after calling pack(). so the effects of the pack() statement will be ignored.
You should let the layout manager figure out the proper size rather than calling setSize on the frame.

You should call pack() just before calling setVisible(), and that should be the last statement in the method that creates the entire GUI.
1 week ago
Oh - I just noticed that myself. The statement inside the loop should be print(), not println().
I would still print the newline even if the parameter is less than 1; otherwise the user might think the program is still thinking...
Of course, one could add an if-else and print an error message if the passed parameter is out of range.
1 week ago
If the value passed as x is less than Zero, the while loop will never be entered.
But maybe there should be a check in order to not print the newline.
1 week ago
Campbell's post is the right approach.

But for the purpose of answering your question, the reason your code does not open a second frame is that your run() method calls logWindow() which creates and tries to display the log window, and then returns immediately before you have had a chance to interact with that window, with authorization still true. The if-test in run() then fails (because authorization is still true), and so nothing else happens.

The contents of the log window might not show up, since you set it visible before you add any content to it.
The call to setVisible(true) should be done AFTER you finish building the contents. 
1 week ago
Note that the if-test is unnecessary. You can just use:
1 week ago
You need to check that the input is positive BEFORE you enter the loop.
Why the check for x < 15? Where does 15 come from?

This can be done without a separate check for the input being positive. Why not start the loop at the input value and decrement it until it reaches zero?
1 week ago
If you want to split on a single space, use " " as the regex. If you want to split on any amount of whitespace (multiple spaces, tab, etc.), then use "\s"
See the documentation for Pattern. at
2 weeks ago

Tim Moores wrote:Given that money generally has at most two decimal places, you might as well make myMoney a float rather than a double.

The number of places after the decimal point is not relevant. For example, the value 17878654.45 has 10 significant figures and cannot be stored in a float without loss of precision.
Money is often represented as a long, specifying the number of cents. 1787865445 easily fits in a long.
1 month ago
You may be thinking of the case where there is an instance variable with the same name as the argument. For example,
Note the use of the  'this' keyword here. That allows you to set the instance variable "value" to refer to the parameter passed in as an argument.

It is a matter of personal preference whether to have parameter names the same as instance variables.Personally, I usually try to avoid that by using separate names:
Note that it is no longer necessary to use the "this" keyword, although you are still allowed to do so.
2 months ago
You don't say what kind of Class yur LoginForm and RegistrationForm are, but you really should be using JDialog for this, with each JDialog specified to be APPLICATION_MODAL.

Then when the dialog is made visible, the user can only interact with that dialog until the dialog is dismissed.
2 months ago

David Ellis Rogers wrote:how do I perform a compile in Eclipse?

Make sure "Project->Build automatically" is checked. Then any time you save an edit it will automatically compile everything.
2 months ago
Since you are (correctly) using doubles, you should not specify PI as 3.14159. Use Math.PI instead.
3 months ago