Originally posted by sven studde:
Well, you can go too far with that as well. For instance, I think this is a case of going too far:
[...]
You can always wrap every java function in a function of your own, but that just creates needless overhead.
Originally posted by Garrett Rowe:
Except by wrapping the method it leaves open the possibility that a different implementation may be used. Perhaps in the future you might decide to use an implementation of a Mersenne Twister instead of java.util.Random to generate random numbers, or for testing you might want to create a mock implementation which overrides the createRandomNumber() method to return a non-random predetermined number. You then only have to change a single method implementation and leave the rest of your code untouched.
Originally posted by sven studde:
In java, you can declare and create a new array in one line like this:
int[] nums = new int[10];
But, that is a two part operation, which can be broken up into its constituent parts:
int[] nums;
nums = new int[10];
The first line declares a variable that can refer to an int array. The second line creates an array and sets nums to refer to the array. However, you don't have to write the second line immediately after the first. In other words, you can create the variable, but not assign anything to it until later:
int[] nums;
...
...
nums = new int[5];
In your case, to make a Players array available to the whole class, you can declare a data member for your class:
private Players[] p;
and then sometime later, like in an initPlayers() method, you can create a Players array and set p to refer to it:
p = new Players[5];
(Note: you might want to set p=null in the constructor for the class, so that you at least initialze p when p is created.)
Originally posted by sven studde:
Additionally, which is something I didn't know you could do in java, you can make the size of the array a variable:
p = new Players[numPlayers];
Therefore, you can set the value of the numPlayers variable equal to the user input from the JOptionsPane.
Originally posted by Ernest Friedman-Hill:
The GUI event-handling thread will keep a program from exiting when main() returns. Using any GUI components will start it, and thereafter to make the program exit, you must call System.exit(0).
Originally posted by Ernest Friedman-Hill:
This line:
myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Arranges for a WindowEventListener to be attached to the JFrame which calls System.exit(0) when you close the window.
The original poster's program is a sort of hybrid thing which just throws up a few dialogs; when main() returns, the program won't exit by itself because the GUI thread (which is a non-daemon thread) is still running. He could just put System.exit(0) at the end of main().
Originally posted by David O'Meara:
"Ludo",
Welcome to the JavaRanch.
We're a friendly group, but we do require members to have valid display names.
Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.
Please edit your profile and correct your display name since accounts with display names get deleted, often without warning
thanks,
Dave