⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client.java

📁 ssd8 exe5 icarnegie exe5
💻 JAVA
字号:
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import java.io.*;
import exe5creator.*;
import exe5.*;
public class Client {

    public static void main( String [] args ) {

	int choice = 0, meetingid = 0;
	String username, password, recipientname, message, start_time,
		end_time, otheruser, description,queryReturn;

	//Setup to read from the keyboard.
	BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));

	//Create an instance of the message center interface.
	TodolistInterface toDoList;
	TodolistCreatorInterface toDoListCreator;
	try {
	    ORB orb = ORB.init( args, null );

	    //Get root naming context.
	    org.omg.CORBA.Object objectReference = orb.resolve_initial_references( "NameService" );
	    NamingContext namingContextReference = NamingContextHelper.narrow( objectReference );

	    //Find the object TodolistCreator.
	    NameComponent nc = new NameComponent("TodolistCreator","");
      	NameComponent path[] = { nc };	       
	    toDoListCreator = TodolistCreatorInterfaceHelper.narrow(namingContextReference.resolve(path));
	   
	    //display the menu 
	    while ( true ) {
		System.out.println( "1. Register a new user" );
		System.out.println( "2. Clear a user's to do list" );
		System.out.println( "3. Delete a to do list item" );
		System.out.println( "4. Add an item to the to do list" );
		System.out.println( "5. Query items from the to do list" );
		System.out.println( "6. Exit" );
		System.out.println( "choose your choice: " );
		choice = Integer.parseInt( keyboard.readLine() );
		
		//Print an error message if the registration fails 
		//or a success message if the registration succeeds	 
		if (choice==1) {
		    System.out.println( "Enter username: " );
		    username = keyboard.readLine();
		    System.out.println( "Enter password: " );
		    password = keyboard.readLine();
		    if (!toDoListCreator.register(username,password)) {
			System.out.println( "Error!" );
		    } else {
			System.out.println( "Success!" );
		    }
		}
		if (choice==2) {
		    System.out.println( "Enter username: " );
		    username = keyboard.readLine();
		    System.out.println( "Enter password: " );
		    password = keyboard.readLine();
		    nc = new NameComponent(username,"");
		    NameComponent path2[] = { nc };
		    toDoList = TodolistInterfaceHelper.narrow(namingContextReference.resolve(path2));
		    if ( toDoList.clear( username, password ) ) {
			System.out.println( " To Do List for " + username + " has been successfully cleared." );
		    } else {
			System.out.println( "Error in clearing to do list for " + username + "!" );
			System.out.println( "Try a different username/password!" );
		    }
		}
		//delete a meeting.
		if ( choice==3 ) {
		    System.out.println( "Enter username: " );
		    username = keyboard.readLine();
		    System.out.println( "Enter password: " );
		    password = keyboard.readLine();
		    System.out.println( "Enter the meetingid of to do list item to delete: " );
		    meetingid = Integer.parseInt( keyboard.readLine() );
		    nc = new NameComponent(username,"");
		    NameComponent path2[] = { nc };
		    toDoList = TodolistInterfaceHelper.narrow(namingContextReference.resolve(path2));
		    if ( toDoList.delete(username, password, meetingid ) ) {
			System.out.println( "List item has been deleted!" );
		    } else {
			System.out.println( "Error in deleting list item!" );
			System.out.println( "Try a different username/password/list item id!" );
		    }
		} 
		    
		//Add an item
		if (choice==4) {
		    System.out.println( "Enter username: " );
		    username = keyboard.readLine();
		    System.out.println( "Enter password: " );
		    password = keyboard.readLine();
		    System.out.println( "Enter the start time" );
		    System.out.println( "For example, 06/01/2008-12:00" );
		    start_time = keyboard.readLine();
		    System.out.println( "Enter the end time" );
		    System.out.println( "For example, 07/01/2008-12:00" );
		    end_time = keyboard.readLine();
		    System.out.println( "Enter the to do list item description" );
		    description = keyboard.readLine();
		    nc = new NameComponent(username,"");
		    NameComponent path2[] = { nc };
		    toDoList = TodolistInterfaceHelper.narrow(namingContextReference.resolve(path2));
		    if ( toDoList.add( username, password, start_time, end_time, description ) ) {
			System.out.println( "To do list item has been added successfully!" );
			} else {
			    System.out.println( "Failed to add list item!" );
			}
		}
		
		//Query a meeting
		if (choice==5) {
		    System.out.println( "Enter username: " );
		    username = keyboard.readLine();
		    System.out.println( "Enter password: " );
		    password = keyboard.readLine();
		    System.out.println( "Enter the start time" );
		    System.out.println( "For example, 06/01/2008-12:00" );
		    start_time = keyboard.readLine();
		    System.out.println( "Enter the end time" );
		    System.out.println( "For example, 07/01/2008-12:00" );
		    end_time = keyboard.readLine();
		    nc = new NameComponent(username,"");
		    NameComponent path2[] = { nc };
		    toDoList = TodolistInterfaceHelper.narrow(namingContextReference.resolve(path2));
		    queryReturn = toDoList.query( username, password, start_time, end_time );
		    if (queryReturn==null || queryReturn.length()==0) {
			System.out.println( "No to-do list items matched the criteria!" );
		    } else {
			System.out.println( "To-do list items matches the criteria: " );
			System.out.println( queryReturn );
		    }
		}
		if (choice==6) {
		    System.exit(0);
		}
	    }
	} catch( Exception e ) {
	    e.printStackTrace();
	}
    }
}







⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -