| | |
| | | package com.netsdk.common; |
| | | package com.ycl.api.DH.common; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.util.NoSuchElementException; |
| | |
| | | import java.util.Vector; |
| | | |
| | | public class CaseMenu { |
| | | |
| | | |
| | | public static class Item { |
| | | private Object object; |
| | | private String itemName; |
| | | private String methodName; |
| | | |
| | | |
| | | public Item(Object object, String itemName, String methodName) { |
| | | super(); |
| | | this.object = object; |
| | |
| | | return methodName; |
| | | } |
| | | } |
| | | |
| | | |
| | | private Vector<Item> items; |
| | | |
| | | public CaseMenu() { |
| | | super(); |
| | | items = new Vector<Item>(); |
| | | } |
| | | |
| | | |
| | | public void addItem(Item item) { |
| | | items.add(item); |
| | | } |
| | | |
| | | |
| | | private void showItem() { |
| | | final String format = "%2d\t%-20s\n"; |
| | | int index = 0; |
| | | int index = 0; |
| | | System.out.printf(format, index++, "exit App"); |
| | | for (Item item : items) { |
| | | System.out.printf(format, index++, item.getItemName()); |
| | | } |
| | | System.out.println("Please input a item index to invoke the method:"); |
| | | } |
| | | |
| | | |
| | | public void run() { |
| | | Scanner scanner = new Scanner(System.in); |
| | | while(true) { |
| | | showItem(); |
| | | try { |
| | | while(true) { |
| | | showItem(); |
| | | try { |
| | | int input = Integer.parseInt(scanner.nextLine()); |
| | | |
| | | if (input <= 0 ) { |
| | |
| | | // System.exit(0); |
| | | break; |
| | | } |
| | | |
| | | |
| | | if (input < 0 || input > items.size()) { |
| | | System.err.println("Input Error Item Index."); |
| | | continue; |
| | | } |
| | | |
| | | |
| | | Item item = items.get(input - 1); |
| | | Class<?> itemClass = item.getObject().getClass(); |
| | | Method method = itemClass.getMethod(item.getMethodName()); |
| | |
| | | continue; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | scanner.close(); |
| | | } |
| | | } |