1. Zachary Boddy's Avatar
    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.
    12-08-2015 05:19 PM
  2. cmakthat's Avatar
    Hey Zachary,

    For enterInt(): Looks good to me. Short and sweet functions are always nice. Looks like you could use a "BufferReader" too, but the way you've done it is a bit simpler.

    For delay(): I might've gone with using "Thread.sleep(n)" instead. If you're just building a console input type application, then it should be fine. If you're goal is to do mobile development eventually, usually delaying the code like that isn't the best idea because it could freeze the application and the user won't know what's going on. What exactly are you using the delay for?

    For drawCircle(): Again, short and sweet. As long as it works, I don't see a problem with this function.

    Hope this was helpful for you.
    12-21-2015 01:00 PM
  3. Zachary Boddy's Avatar
    Hey Zachary,

    For enterInt(): Looks good to me. Short and sweet functions are always nice. Looks like you could use a "BufferReader" too, but the way you've done it is a bit simpler.

    For delay(): I might've gone with using "Thread.sleep(n)" instead. If you're just building a console input type application, then it should be fine. If you're goal is to do mobile development eventually, usually delaying the code like that isn't the best idea because it could freeze the application and the user won't know what's going on. What exactly are you using the delay for?

    For drawCircle(): Again, short and sweet. As long as it works, I don't see a problem with this function.

    Hope this was helpful for you.
    Hey thanks for your advice. I'll keep the enterInt and drawCircle methods the same. About the delay method, I was planning to use it as a general "go-to" delay method for, well, anything. Recently I've been playing with simple animations and I've been using that delay method to do it. If there's a better, more reliable way to do a delay method I'd love some more detail on the topic.
    12-21-2015 05:21 PM

Similar Threads

  1. Rich Capture question.
    By MerlotC in forum Microsoft Lumia 950
    Replies: 23
    Last Post: 06-15-2016, 08:16 AM
  2. Cuple question to clear things a bit
    By Terepin in forum Microsoft Lumia 550
    Replies: 1
    Last Post: 12-07-2015, 08:53 AM
  3. Thunderbolt 2/USB 3.1/Dell XPS15 question
    By identity-x in forum Microsoft Lumia 950 XL
    Replies: 0
    Last Post: 12-06-2015, 01:12 PM
  4. Replies: 0
    Last Post: 12-06-2015, 08:46 AM
  5. Some questions from a brand new windows 10 mobile user
    By rohit bhattacharjee in forum Windows 10 Mobile
    Replies: 4
    Last Post: 12-05-2015, 10:41 PM
LINK TO POST COPIED TO CLIPBOARD