-
February 4th, 2004, 12:40 AM
#1
Member
Java Code Help
Hi
Ive got the following code in java and would like to modify it so that the user can define how many balls are displayed in the Balls window.
Anyone know how i do this ??
thanks
import BallsLib.*;
public class OneBall
{
public static void main (String args[])
{
int maxNumBalls = 1 ;
BallsFrame f;
f = new BallsFrame (maxNumBalls) ;
f.addBalls();
}
}
-
February 4th, 2004, 07:39 AM
#2
Um.... it would be nice if you were to post the classes with source, or at least some api documentation.
EDIT: Sorry, I didn't look at your code properly. Yes, it should be possible. Since this seems to be a command line app, just do this:
Code:
import BallsLib.*;
public class OneBall
{
public static void main (String args[])
{
if(args.length==1)
int maxNumBalls = Integer.parseInt(args[0]);
else
int maxNumBalls = 1;
BallsFrame f;
f = new BallsFrame (maxNumBalls) ;
f.addBalls();
}
}
Then the program would be compiled with javac OneBall.java and run with java OneBall <number of balls>. For example, java OneBall 20
Cheers,
cgkanchi
-
February 9th, 2004, 11:49 AM
#3
Member
Is there not a way to modify the code i posted so that the user is asked to input the max number of balls they want into the console window, and then what they enter is used to display the number of balls they want ?
thanks
-
February 11th, 2004, 12:07 AM
#4
import BallsLib.*;
public class OneBall
{
public static void main (String args[])
{
int maxNumBalls = 1 ;
BallsFrame f;
f = new BallsFrame (maxNumBalls) ;
f.addBalls();
}
}
I am a little rusty in my java but here goes.
import javax.swing.*;
import BallsLib.*;
public class OneBall
{
public static void main (String args[])
{
int amount;
amount=Integer.parseInt( JOptionPane.showInputDialog("Enter number of balls: "));
BallsFrame f;
f = new BallsFrame (amount) ;
f.addBalls();
}
}
Now it is a user defined amount of balls. Hoped that helped
[shadow]l3aDmOnKeY[/shadow]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|