1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| package Client; import InterFace.*; import java.rmi.Naming; import java.util.ArrayList; import java.util.Scanner;
public class MyRMIClient { public static void Print_Tip(){ System.out.println("选择操作代号完成操作"); System.out.println("1:add args:book b"); System.out.println("2:queryByID args:int bookID"); System.out.println("3:queryByName args: String name"); System.out.println("4:delete args:int BookID"); System.out.println("5: print args:null"); System.out.println("6: exit"); } public static void main(String args[]) {
try { String name = "rmi://127.0.0.1:6600/BookSystem"; BookSystemInfo BookSystem=( BookSystemInfo)Naming.lookup(name);
System.out.println("查找服务端成功"); Scanner input=new Scanner(System.in); int number = 6; Print_Tip(); while ((number = input.nextInt())!=6){ switch (number){ case 1:{ System.out.println("输入ID和名字"); int bookID = input.nextInt(); String bookName = input.next(); Book newbook = new Book(bookName,bookID); boolean res = BookSystem.add(newbook); if(res==true){ System.out.println("添加成功"); } else{ System.out.println("添加失败"); } } break; case 2:{ System.out.println("输入ID"); int bookID = input.nextInt(); Book res = BookSystem.queryByID(bookID); if(res==null){ System.out.println("无该ID号的书籍"); } else{ System.out.println("书籍信息如下"); res.Print_content(); } } break; case 3:{ System.out.println("输入name"); String bookName = input.next(); ArrayList<Book> res = BookSystem.queryByName(bookName); if(res==null){ System.out.println("同名书籍数目为零"); } else { System.out.println("查询结果如下"); for (Book b : res) { b.Print_content(); } } } break; case 4:{ System.out.println("输入ID"); int bookID = input.nextInt(); boolean res = BookSystem.delete(bookID); if(res==true){ System.out.println("删除成功"); } else{ System.out.println("删除失败"); } } break; case 5:{ System.out.println("调用该方法只是在服务端打印书籍列表,客户端不显示"); BookSystem.print(); } break; }
}
} catch (Exception e) { System.err.println("??? exception:"); e.printStackTrace(); } } }
|