Because it is inconvenient to add running parameters in the eclipse running configuration, it is recommended to export the debugged java project as a jar package that can be run. Then open the jar in the command line and use the "java -jar <package name> <main function. Parameter 1 Parameter 2 ......> ". The help command in the figure below is the first element arg[0] of the parameter array arg[] when the main function is executed.The parameters are separated by spaces, followed by arg[1], arg[2]. Knowing this, making a java command line navigation menu is simple.In order to facilitate the operation, the extremely guest also produced a GUI for this experiment, supporting GUI, command line dual interface mode operation and application.The benefits of the command line may only be understood by programmers. Its greatest benefit, personally believed, is that it can be batched. This is something that GUI users cannot understand.
Effect preview:
java command line navigation menu
MeetingClient.java
The following code performs the methods defined in the previous article by matching the main function parameters entered by the user.Entering the GUI and not entering parameters will start the GUI mode. java command line navigation menu 2
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
Package cn.wangbaiyuan; Import java.io.BufferedReader; Import java.io.IOException; Import java.io.InputStreamReader; Import java.rmi.Naming; Import java.rmi.NotBoundException; Import java.sql.SQLException; /** * RMI Conference Client * @author Wang Baiyuan * *{@linkplain http://wangbaiyuan.cn} */ Public class MeetingClient { Public static void main(String args[]) throws IOException{ Int cmdLength=args.length; MeetingInterface meeting; If(cmdLength==0){ LoginGUI.show(null); }else { String note="RMI meeting client © Wang Baiyuan - command line version:n" + "1. Help:nthelpn" + "2. User Registration:ntregister [username] [password]n" + " 3. Add a meeting:ntadd [your username] [your password] [Who is invited?His username] [start time] [end time] [meeting title]n" + "t Time format: 2015-06-05 22:29:19n" + "4. Query meeting:ntquery [your username] [your password][start time][end time]n" + "5. Deleting the conference:ntdelete [your username] [your password] [conference ID]n" + "6. Clear Meeting:ntclear [username] [password]n" + "7. About this program:ntaboutn" + "8. Exit:n quitnt" + "9.GUI mode:n GUInt" + "Please enter the command:"; String about="RMI meeting client © Wang Baiyuan - command line version:n" + "Author: Wang Bai Yuan n" + "Personal Website: http://wangbaiyuan.cnn" + "Run Mode: GUI and Command Line Dual Environmentn" + "Program Description: Create a distributed agenda sharing service using Java RMI."" + "Different users can use this shared agenda service to perform queries, add, and delete" + "The operation of the conference.The server supports functions such as registration and clearing of conferences;"; Try { Meeting=(MeetingInterface) Naming.lookup(LoginGUI.getRmiURL()); Switch(args[0]){ Case "register": If(cmdLength==3){ meeting.addMeetingUsers(args[1], args[2]); }else{ System.out.println("Command parameter errorn" + "User Registration: ntregister [username] [password]n"); } Break; Case "add": If(cmdLength==9){ meeting.addMeetings(args[1], args[2], args[3], args[4], args[5]+" " +args[6], args[7]+" "+args[8]); }else{ System.out.println("Command parameter errorn" + "Add conference:ntadd [your username] [your password] [Who is invited?His username] [meeting title] [start time] [end time] n"); } Break; Case "query": If(cmdLength==7){ If(meeting.LoginMeetings(args[1], args[2])) meeting.searchrMeetings(args[3]+" "+ args[4],args[5]+" "+ args[6]); }else{ System.out.println("Command parameter errorn" + "Query Conference: ntquery [username] [password] [start time] [end time]n"); } Break; Case "delete": If(cmdLength==4){ If(meeting.LoginMeetings(args[1], args[2])) meeting.deleteMeetings(args[1], args[3]); }else{ System.out.println("Command parameter errorn" + "Delete meeting:ntdelete [your username] [your password] [conference ID]n"); } Break; Case "clear": If(cmdLength==3){ If(meeting.LoginMeetings(args[1], args[2])) meeting.clearMeetings(args[1]); }else{ System.out.println("Command parameter errorn" + "Clear Meeting:ntclear [username] [password]n"); } Break; Case "about": System.out.println(about);break; Case "GUI": LoginGUI.show(null);break; Case "help": System.out.println(note);break; Case "quit": LoginGUI.show(null);break; } } Catch (NotBoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BYException e) { // TODO Auto-generated catch block System.out.println(e.getMessage()); } Catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } |
Series links:
SSD8_Ex3 [JAVA_RMI Service] (1) Overview of RMI and Network APIs
SSD8_Ex3[JAVA_RMI](2) Remote Interface Declaration
SSD8_Ex3 [JAVA_RMI] (3) Open RMI Service
SSD8_Ex3 [JAVA_RMI] (4) conference database table
SSD8_Ex3 [JAVA_RMI] (5) database connection and meeting method definition
SSD8_Ex3 [JAVA_RMI] (6) Create Command Line Navigation Menu
This article has been printed on copyright and is protected by copyright laws. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain the authorization. If you feel that this article is useful to you, you can click the "Sponsoring Author" below to call the author!
Reprinted Note Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/java-rmi-6-making-the-command-line-navigation-menu-2.html
No Comment