|
| 1 | +package com.test; |
| 2 | + |
| 3 | +import java.util.InputMismatchException; |
| 4 | +import java.util.Scanner; |
| 5 | + |
| 6 | +public class Main { |
| 7 | + |
| 8 | + public static void main(String[] args) { |
| 9 | + MyThread t = null; |
| 10 | + int option = 0; |
| 11 | + String guide = "|| Please insert option number"; |
| 12 | + String select1 = "| 1:start(120s)"; |
| 13 | + String select2 = "| 2:start with custom duration"; |
| 14 | + String select3 = "| 3:pause the script"; |
| 15 | + String select4 = "| 4:stop and terminate"; |
| 16 | + guide = rightPadding(guide, 70, ' ') + "||\n"; |
| 17 | + select1 = rightPadding(select1, 70, ' ') + "||\n"; |
| 18 | + select2 = rightPadding(select2, 70, ' ') + "||\n"; |
| 19 | + select3 = rightPadding(select3, 70, ' ') + "||\n"; |
| 20 | + select4 = rightPadding(select4, 70, ' '); |
| 21 | + |
| 22 | + while (true) { |
| 23 | + System.out.println("=========================Mouse Auto Move Script========================="); |
| 24 | + System.out.println(guide + select1 + select2 + select3 + select4); |
| 25 | + System.out.println("========================================================================"); |
| 26 | + Scanner input = new Scanner(System.in); |
| 27 | + try { |
| 28 | + option = input.nextInt(); |
| 29 | + } catch (InputMismatchException e) { |
| 30 | + option = 999; |
| 31 | + } |
| 32 | + if (option == 1) { |
| 33 | + for (int i = 0; i < 50; i++) { |
| 34 | + System.out.println("\n"); |
| 35 | + } |
| 36 | + System.out.println("=========================Script Started========================="); |
| 37 | + if (t != null) { |
| 38 | + t.interrupt(); |
| 39 | + } |
| 40 | + t = new MyThread(); |
| 41 | + t.start(); |
| 42 | + } else if (option == 2) { |
| 43 | + for (int i = 0; i < 50; i++) { |
| 44 | + System.out.println("\n"); |
| 45 | + } |
| 46 | + System.out.println("===============Input the detect duration(second)================="); |
| 47 | + if (t != null) { |
| 48 | + t.interrupt(); |
| 49 | + } |
| 50 | + Long time = input.nextLong(); |
| 51 | + t = new MyThread(time); |
| 52 | + t.start(); |
| 53 | + } else if (option == 3) { |
| 54 | + for (int i = 0; i < 50; i++) { |
| 55 | + System.out.println("\n"); |
| 56 | + } |
| 57 | + if (t == null) { |
| 58 | + System.out.println("*********You have to start task first for use pause function"); |
| 59 | + } else { |
| 60 | + System.out.println("========================Script Paused========================="); |
| 61 | + t.interrupt(); |
| 62 | + t = null; |
| 63 | + } |
| 64 | + |
| 65 | + } else if (option == 4) { |
| 66 | + if (t != null) { |
| 67 | + t.interrupt(); |
| 68 | + } |
| 69 | + t = null; |
| 70 | + input.close(); |
| 71 | + System.out.println("=========================application terminated========================="); |
| 72 | + break; |
| 73 | + } else if (option == 999) { |
| 74 | + System.out.println( |
| 75 | + "********************Your Input type error********************\n********************Please type number in.********************"); |
| 76 | + |
| 77 | + } else { |
| 78 | + System.out.println("********************Please use the numbers on the menu********************"); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + } |
| 83 | + |
| 84 | + private static String rightPadding(String str, int length, char padChar) { |
| 85 | + if (str == null) { |
| 86 | + str = ""; |
| 87 | + } |
| 88 | + if (str.length() > length) { |
| 89 | + return str; |
| 90 | + } |
| 91 | + String pattern = "%-" + length + "s"; |
| 92 | + return String.format(pattern, str).replace(' ', padChar); |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments