hello.java

来自「Java p2p程序设计2002年版」· Java 代码 · 共 76 行

JAVA
76
字号
package net.jxta.impl.shell.bin.hello;

import net.jxta.impl.shell.*;

import java.io.*;
import java.util.*;

import net.jxta.pipe.*;
import net.jxta.document.*;
import net.jxta.protocol.*;
import net.jxta.endpoint.*;


/**
 * Our first shell command
 */
public class hello extends ShellApp {
    
    /**
     * For access to the shell environment
     */
    ShellEnv env;
    
    public hello() {
    }
    
    /**
     * Called when the shell application stops running.
     */
    public void stopApp () {
    }
    
    /**
     * Called when the shell application is launched in the shell.
     */
    public int startApp (String[] args) {
         
        env = getEnv();
        
        if(args.length==2 && "-store".equals(args[0])) {
            
            // Create a new shell object and add it to the environment
            // variable space
            env.add("helloname", new ShellObject(null,args[1]));
            println("stored name");
        }
        if(args.length==0) {
            // Retrieve the shell object with label 'helloname'
            // If it's not null use it
            ShellObject nameObj = env.get("helloname");
            if(nameObj==null) {
                println ("Hello World!!");
            } else {
                println("Hi "+(String)nameObj.getObject()+"!");
            }
        }
        
        // Return no error
        return ShellApp.appNoError;              
    }
    
    /**
     * Returns a description of this command.
     */
    public String getDescription() {
        return "Says hello to the world!";
    }
    
    /**
     * Called to trigger help (e.g. when doing a 'man hello')
     */
    public void help() {
        println("hello [-store name]");        
    }
}

⌨️ 快捷键说明

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