libraryclient.java

来自「简化的图书查询系统,服务器端和客户端都有。采用CORBA实现.」· Java 代码 · 共 103 行

JAVA
103
字号
import LibraryApp.*;
import java.lang.Throwable.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;
import java.io.IOException;
public class LibraryClient
{
  static Library libraryImpl;

  public static void main(String args[]){
     try{
	ORB orb = ORB.init(args, null);
        org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); 
        NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
        String name1 = "Library";
        libraryImpl = LibraryHelper.narrow(ncRef.resolve_str(name1));
        System.out.println("输入你要查询书的名字");
        BufferedReader stdin = new BufferedReader(new  InputStreamReader(System.in));
        String str = stdin.readLine();
        String strRece=libraryImpl.requery();
        String name ="name";
        String author="author";
        String press ="press";
        String show_name="";
        String show_author="";
        String show_press="";
        String [] strNew = strRece.split(" ");
        int i = -1;int k = 0;
        System.out.print("查询结果如下:");
         System.out.print("\r\n");
        System.out.print("BookName");
        System.out.print("   Author");
         				    
        System.out.print("   Press");
        System.out.print("\r\n");
          
        FileOutputStream   out=new   FileOutputStream("result.txt");   
        out.write("BookName".getBytes());   
        out.write("  Author".getBytes());
       out.write("  Press".getBytes());
        out.write("\r\n".getBytes());
        while (k< strNew.length -1)
        {
        	while(strNew[k].equals(name)==false && k< strNew.length -1)
        	 { k++;} 
        	if( k == strNew.length -1)
        	{break;}
        	else
        	{
        		show_name =strNew[k+1];
        		i =show_name.indexOf(str);
        		if(i>-1)
        		{
        			k++;
        			while(strNew[k].equals(author)==false && k< strNew.length -1)
        			{k++;}
        			if( k == strNew.length -1) break;
        			else
        			{
        				show_author = strNew[k+1];
        				k++;
        				while(strNew[k].equals(press)==false&& k< strNew.length -1)
            			{k++;}
        				if( k == strNew.length -1) break;
        				else
        				{
        				    show_press = strNew[k+1];
        				   
                                            System.out.print("   ");
        				    System.out.print(show_name);
                                            out.write(show_name.getBytes());
                                            System.out.print("    ");
                                            out.write("    ".getBytes());
        				    System.out.print(show_author);
                                            out.write(show_author.getBytes());
                                            System.out.print("    "); 
                                            out.write("    ".getBytes());
        				   System.out.println(show_press);
                                            out.write(show_press.getBytes());
                                            
                                             System.out.print("\r\n");
                                             out.write("\r\n".getBytes());
        				    k++;
        				}
        			 }	
        		 }
        		 else{k++; }
        	  k++;
        	}
       
        }
out.close();   
       libraryImpl.shutdown();

	  } 
     catch (Exception e) {
        System.out.println("ERROR : " + e) ;
	     e.printStackTrace(System.out);
	  } 
  } 
} 

⌨️ 快捷键说明

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