Hey guys I'm a relatively new Java programmer (if you can even call me that yet) and I have a few questions. I've been collecting all my useful methods and such and compiling them into a utility class and I was just wondering if there were better ways to do the things I'm doing. More specifically:
public static int enterInt()
{
Scanner input = new Scanner(System.in);
int t = input.nextInt();
return t;
}
I'm wondering if there's a better way to ask the user for an integer and then return that value to the user. And:
public static void delay(int n)
{
long startDelay = System.currentTimeMillis();
long endDelay = 0;
while (endDelay - startDelay < n)
endDelay = System.currentTimeMillis();
}
I'm wondering if there's a better way to do a delay. I want a reliable delay. Also:
public static void drawCircle(Graphics g, int x, int y, int r)
{
int d = r * 2;
g.drawOval(x - r, y - r, d, d);
}
This is how I currently draw a circle. That's all for now. Thanks in advance.
public static int enterInt()
{
Scanner input = new Scanner(System.in);
int t = input.nextInt();
return t;
}
I'm wondering if there's a better way to ask the user for an integer and then return that value to the user. And:
public static void delay(int n)
{
long startDelay = System.currentTimeMillis();
long endDelay = 0;
while (endDelay - startDelay < n)
endDelay = System.currentTimeMillis();
}
I'm wondering if there's a better way to do a delay. I want a reliable delay. Also:
public static void drawCircle(Graphics g, int x, int y, int r)
{
int d = r * 2;
g.drawOval(x - r, y - r, d, d);
}
This is how I currently draw a circle. That's all for now. Thanks in advance.