TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
/***********************************************
* NETDEMO.CLASS (MAIN KERNEL OF "MOLECULE" VOS)
*
* WRITTEN BY "Fubin"
* COMPILED IN JDK1.5.*
* My MSN:yonghe169@163.com
*
*这是一个十分重要的模仿Dos界面的系统!非常重要。可以
* 用在很多处理输入程序的地方
*例如:Sisco等,可以写专门的接口工作程序
***********************************************/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import java.io.*;
import java.text.*;
- 运行图:
- [img]http://img.javaxxz.com/2014/10/2/082124828.gif[/img]
- public class NetDemo extends Panel implements KeyListener{
- static Frame myFrame;
- TextField tf;
- TextArea ta;
- Panel p1,p2,p3;
- Scrollbar sb1,sb2;
- String currentPath=System.getProperty("user.dir");
- String prompt=">",Temp="",drive_Name="";
- int commandNum=0,tempCommand=0;
- Object val;
- ArrayList ll=new ArrayList();
- String currentContent="",path="";
- boolean editOn;
- public NetDemo() {
- ta=new TextArea(25,75);
- tf=new TextField(75);
- p1=new Panel();
- p1.setBackground(Color.lightGray);
- p2=new Panel();
- p2.setBackground(Color.lightGray);
- setLayout(new BorderLayout());
- p1.add(ta,BorderLayout.NORTH);
- add(p1,BorderLayout.NORTH);
- p2.add(tf,BorderLayout.NORTH);
- add(p2,BorderLayout.SOUTH);
- Font f=new Font("Monospaced",Font.PLAIN,15);
- ta.setFont(f);
- tf.setFont(f);
- ta.setBackground(Color.white);
- ta.setForeground(Color.black);
- tf.setBackground(Color.white);
- tf.setForeground(Color.black);
- ta.append("Title: Molecule Virtual OS
- ");
- ta.append("Version: Pre-beta Kernel, JVM version 1.2/1.3
- ");
- ta.append("Written by: Amitava Sen
- ");
- ta.append("Contact: write2sen@hotmail.com
- ");
- ta.append("Dated: February, 2001.
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(true);
- tf.addKeyListener(this);
- requestFocus();
- tf.requestFocus();
- }
- void p(String s){ta.append(s);}
- public void keyTyped(KeyEvent ke) {};
-
- public void keyReleased(KeyEvent ke) {};
- public void keyPressed(KeyEvent ke) {
-
- if (editOn==false) commandControl(ke);
-
- if (editOn==true) edit(ke);
- }
- //////////////////////////////////////////////////
- ////////////////// EDIT MODE /////////////////////
- //////////////////////////////////////////////////
- protected void edit(KeyEvent ke) {
- editOn=true;
- char c = ke.getKeyChar();
- String commandEnter=tf.getText();
- StringTokenizer tokenizer=new StringTokenizer(commandEnter);
- if (c=="
- ") {
-
- if (commandEnter.equals("exit")) {
- ta.setText(currentContent);
- //ta.setEditable(false);
- tf.setText("");
- editOn=false;
- ta.append(currentPath+prompt);
- myFrame.setTitle("Molecule (NetDemo Console) - Type "help" or "?" for Help");
- }
- else if (commandEnter.startsWith("save") || commandEnter.startsWith("save ")) {
-
- String token=tokenizer.nextToken();
- String taContent=ta.getText();
- char opchar;
- int count,countLimit=taContent.length();
-
- while(tokenizer.hasMoreTokens()){
- try {
- token=tokenizer.nextToken();
-
- FileOutputStream fout=new FileOutputStream(drive_Name+currentPath+"/"+token);
-
- for (count=0;count< countLimit;count++){
- opchar=taContent.charAt(count);
- fout.write((int)opchar);
-
- }
- fout.close();
-
- }catch(Exception e){
- ta.append("Error: Can"t save program ""+token+""
- ");
- }
- }
-
- tf.setText("");
- tf.requestFocus();
- }
- else {
- tf.setText("");
- ta.requestFocus();
- }
- }
- }
- //////////////////////////////////////////////////
- /////////////// COMMAND MODE /////////////////////
- //////////////////////////////////////////////////
- protected void commandControl(KeyEvent ke) {
- editOn=false;
- char c = ke.getKeyChar();
- int key=ke.getKeyCode();
-
- if (key==KeyEvent.VK_UP) {
- tempCommand=tempCommand-1;
- try {
- val=ll.get(tempCommand);
- String commandSel=(String)val;
- tf.setText("");
- tf.setText(commandSel);
- }catch(Exception e){}
-
- }
- if (key==KeyEvent.VK_DOWN) {
- tempCommand=tempCommand+1;
- try {
- val=ll.get(tempCommand);
- String commandSel=(String)val;
- tf.setText("");
- tf.setText(commandSel);
- }catch(Exception e){}
-
- }
- if (c=="
- "){
-
- String ta_Address="",command="";
- String commandEnter=tf.getText();
- commandEnter=commandEnter.trim();
- int i,commandMode;
- if (!commandEnter.equals("")) {
- ll.add(commandEnter);
- commandNum=commandNum+1;
- tempCommand=tempCommand+1;
- //System.out.println(ll+" "+commandNum);
- }
-
- try {
- String tmp1=currentPath+"/"+commandEnter;
- String tmp2=tmp1.replace("","/");
- StringTokenizer st1=new StringTokenizer(tmp2);
- String tmp3=st1.nextToken();
- String tmp4=st1.nextToken();
- tmp2=tmp3+tmp4;
- //System.out.println(tmp2);
- }catch(Exception e){}
- tf.setText("");
- StringTokenizer tokenizer=new StringTokenizer(commandEnter);
-
- ////////////// IP ////////////////////
- if (commandEnter.startsWith("ip") || commandEnter.startsWith("ip "))
- {
- int ServerError=0;
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- //ta.setEditable(false);
- String token=tokenizer.nextToken();
-
- while(tokenizer.hasMoreTokens()){
- token=tokenizer.nextToken();
- try{
- InetAddress SW[]=InetAddress.getAllByName(token);
- for(i=0;i< SW.length;i++)
- ta_Address=ta_Address+SW[i]+"
- ";
- ta.setEditable(true);
- ta.append(ta_Address+"
- ");
- //ta.setEditable(false);
- }catch(Exception e)
- {
- ServerError=1;
- String cannotFindServer="";
- cannotFindServer=token;
- ta.append("Error: Can"t find server ""+cannotFindServer+""
- ");}
- }
- if (ServerError==1){
- ta.append(currentPath+prompt);
- tf.requestFocus();
- }
-
- }
-
- ////////////// URL INFORMATION //////////////////
- if (commandEnter.startsWith("urlinfo") || commandEnter.startsWith("urlinfo "))
- {
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- //ta.setEditable(false);
- String token=tokenizer.nextToken();
-
- while(tokenizer.hasMoreTokens()){
- token=tokenizer.nextToken();
- try{
- URL hp=new URL(token);
- URLConnection hpCon=hp.openConnection();
- ta.append("""+token+"" available data:
- ");
- ta.append("Date: "+new Date(hpCon.getDate())+"
- ");
- ta.append("Content/Type: "+hpCon.getContentType()+"
- ");
- ta.append("Last Modified: "+new Date(hpCon.getLastModified())+"
- ");
-
- ta.setEditable(true);
- ta.append(ta_Address+"
- ");
- //ta.setEditable(false);
- }catch(Exception e)
- {
- String cannotFindServer="";
- cannotFindServer=token;
- ta.append("Error: Can"t find server ""+cannotFindServer+""
- ");
- ta.append("Usage: urlinfo http://"+cannotFindServer+"
- ");}
- }
- ta.append(currentPath+prompt);
- tf.requestFocus();
-
- }
-
- ////////////// RUN ////////////////////
- else if (commandEnter.startsWith("run ") || commandEnter.startsWith("run"))
- {
- int runError=0;
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- //ta.setEditable(false);
- String token=tokenizer.nextToken();
- String ta_Run="";
- while(tokenizer.hasMoreTokens()){
- token=tokenizer.nextToken();
- Runtime r=Runtime.getRuntime();
- Process p=null;
- try{
- p=r.exec(token);
- ta_Run=ta_Run+token+"
- ";
- ta.setEditable(true);
-
- }catch(Exception e){
- String cannotRunFile="";
- cannotRunFile=token;
- ta.append("Error: Can"t run program ""+cannotRunFile+""
- ");
- }
-
- }
- ta.append("The file(s) started are:
- "+ta_Run+"
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
-
-
- ////////////// WHOIS ////////////////////
- else if (commandEnter.startsWith("whois ") || commandEnter.startsWith("whois"))
- {
- int whois=0,ch;
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- //ta.setEditable(false);
- String token=tokenizer.nextToken();
- String ta_Whois="",Whois="";
- while(tokenizer.hasMoreTokens()){
- token=tokenizer.nextToken();
- try{
- Socket s=new Socket("internic.net",43);
- InputStream in=s.getInputStream();
- OutputStream out=s.getOutputStream();
- Whois=token+"
- ";
- byte buf[]=Whois.getBytes();
- out.write(buf);
- while ((ch=in.read())!=-1) {
- ta_Whois=ta_Whois+(char)ch;
- }
- ta.append(ta_Whois);
- s.close();
- }catch(Exception e){
- String cannotFindWhois="";
- cannotFindWhois=token;
- ta.append("Error: Can"t find server ""+cannotFindWhois+""
- ");
- }
- }
- //s.close();
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
-
-
- }
-
- ////////////// FIND FILE /////////////
- else if (commandEnter.startsWith("find ") || commandEnter.startsWith("find"))
- {
- boolean findFile;
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- String token=tokenizer.nextToken();
- String ta_FileExists="",ta_FileDoesNotExist="";
-
- while(tokenizer.hasMoreTokens()){
- token=tokenizer.nextToken();
- try{
- File isHere=new File(token);
- findFile=isHere.exists();
- if (findFile==true)
- {
- ta_FileExists=ta_FileExists+token+"
- ";
- }
- else {
- ta_FileDoesNotExist=ta_FileDoesNotExist+token+"
- ";
- }
-
- }catch(Exception e){ta.append("Error: Can"t execute command "find"
- ");}
- }
- ta.append("The file(s) exist(s):
- ");
- ta.append(ta_FileExists);
- ta.append("The file(s) do(es) not exist(s):
- ");
- ta.append(ta_FileDoesNotExist+"
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
-
- ////////////// BLACK VIDEO ///////////
- else if (commandEnter.equalsIgnoreCase("bv")) {
- ta.setBackground(Color.black);
- tf.setBackground(Color.black);
- ta.setForeground(Color.lightGray);
- tf.setForeground(Color.lightGray);
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
- ////////////// NORMAL VIDEO ///////////
- else if (commandEnter.equalsIgnoreCase("nv")) {
- ta.setBackground(Color.white);
- tf.setBackground(Color.white);
- ta.setForeground(Color.black);
- tf.setForeground(Color.black);
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
-
- ////////////// ORANGE VIDEO ///////////
- else if (commandEnter.equalsIgnoreCase("ov")) {
- ta.setBackground(Color.black);
- tf.setBackground(Color.black);
- ta.setForeground(Color.orange);
- tf.setForeground(Color.orange);
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
- ////////////// YELLOW VIDEO ///////////
- else if (commandEnter.equalsIgnoreCase("yv")) {
- ta.setBackground(Color.black);
- tf.setBackground(Color.black);
- ta.setForeground(Color.yellow);
- tf.setForeground(Color.yellow);
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
- ////////////// GREEN VIDEO ///////////
- else if (commandEnter.equalsIgnoreCase("gv")) {
- ta.setBackground(Color.black);
- tf.setBackground(Color.black);
- ta.setForeground(Color.green);
- tf.setForeground(Color.green);
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
- ////////////// DATE ////////////////////
- else if (commandEnter.equalsIgnoreCase("date")) {
- Date date=new Date();
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- ta.append("Current date: "+date+"
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- tf.requestFocus();
- }
- ////////////// CLS ////////////////////
- else if (commandEnter.equalsIgnoreCase("cls")) {
- ta.setText("");
- ta.setText(currentPath+prompt);
- tf.requestFocus();
- }
-
- /////////// DIRECTORY ///////////////
- else if (commandEnter.startsWith("dir ")){
- int j=0;
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
-
- try{
- String token=tokenizer.nextToken();
- token=tokenizer.nextToken();
- File dir=new File(token);
- Temp=dir.getPath();
- ta.append("Directory: "+dir.getPath()+"
- ");
- p(dir.exists()?"":"The directory does"nt exist
- ");
- String[] fileNames;
- fileNames=dir.list();
-
- for (j=0;j<=fileNames.length;j++) {
- int fileSize=fileNames[j].length();
- ta.append(fileNames[j]+" , "+"("+fileSize+" bytes)
- ");
- }
-
- }catch(Exception e){}
-
- ta.append("
- Total Files: "+j);
- ta.append("
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
-
- ////////////////////////////////////////////////
- else if (commandEnter.equalsIgnoreCase("dir")){
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
-
- int j=0;
- try{
- File dir=new File(drive_Name+currentPath);
- ta.append("
- Files
- ------
- ");
-
- String[] fileNames;
- fileNames=dir.list();
-
- for (j=0;j<=fileNames.length;j++) {
- //File f=new File(drive_Name+currentPath+fileNames[j]);
- //System.out.println(currentPath);
- File f=new File(fileNames[j]);
- //if (f.isDirectory()) {
- //ta.append(fileNames[j]+" , (directory)
- ");
- //int fileSize=fileNames[j].length();
- //long fileSize=f.length();
- //long modTime=f.lastModified();
- //ta.append(fileNames[j]+" , "+"("+fileSize+" bytes)
- ");
- ta.append(fileNames[j]+"
- ");
- //if (fileSize==0)ta.append(fileNames[j]+" , "+"(dir)
- ");
- //}
- //else {
- // ta.append(fileNames[j]+" , (file)
- ");
- //}
- }
-
- }catch(Exception e){}
-
- ta.append("
- Total Files: "+j);
- ta.append("
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
-
- ////////////// CHANGE DIRECTORY //////////////
- else if (commandEnter.startsWith("cd ")) {
-
- String ta_List="",currentDir="";
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
-
- try{
- String token=tokenizer.nextToken();
- token=tokenizer.nextToken();
-
- File cd=new File(drive_Name+currentPath+"/"+token);
- path=drive_Name+currentPath+"/"+token;
- if (cd.exists()==true)currentPath=path;
- if (cd.exists()==false) ta.append("Error: File does"nt exist
- ");
-
- }catch(Exception e){ta.append("Error: Can"t execute command "cd"
- "); }
-
- ta.append("
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- tf.requestFocus();
- }
- ////////////////////////////////////////////////
- else if (commandEnter.equalsIgnoreCase("cd"))
- ta.append(commandEnter+"
- "+System.getProperty("user.dir")+"
- "+currentPath+prompt);
-
- ////////////////////////////////////////////////
- else if (commandEnter.equalsIgnoreCase("cd..")){
- String ta_List="",currentDir="",rootDir="";
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- try {
- File dir=new File(currentPath);
- if (dir.exists()==false)ta.append("Error: Can"t change directory
- ");
- currentPath=dir.getParent();
- rootDir=dir.getPath();
- if (currentPath==null) {currentPath=rootDir;}
-
- }catch(Exception e){ta.append("Error: Can"t execute command "cd"
- ");}
- ta.append("
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- tf.requestFocus();
- }
- //////////////////// SHOW FILE //////////////////
- else if (commandEnter.startsWith("show ") || commandEnter.startsWith("show"))
- {
- int ic;
-
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- String token=tokenizer.nextToken();
- String fileContent="";
-
- while(tokenizer.hasMoreTokens()){
- token=tokenizer.nextToken();
-
- try{
- FileInputStream fin =new FileInputStream(drive_Name+currentPath+"/"+token);
-
- do {
- ic=fin.read();
- if (ic!=-1) fileContent=fileContent+(char)ic;
- } while(ic!=-1);
- fin.close();
- ta.append(fileContent);
- fileContent="";
-
- }catch(Exception e){
- String cannotShowFile="";
- cannotShowFile=token;
- ta.append("Error: Can"t show file ""+cannotShowFile+""
- ");
- }
- }
-
- ta.append("
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
-
-
- }
-
- //////////////////// COPY FILE //////////////////
- else if (commandEnter.startsWith("copy ") || commandEnter.startsWith("copy"))
- {
- int ic;
-
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
-
- String fileContent="";
- FileInputStream fin;
- FileOutputStream fout;
-
- try{
- String token=tokenizer.nextToken();
- token=tokenizer.nextToken();
- fin=new FileInputStream(drive_Name+currentPath+"/"+token);
-
- token=tokenizer.nextToken();
- fout=new FileOutputStream(drive_Name+currentPath+"/"+token);
-
- do {
- ic=fin.read();
- if (ic!=-1) fout.write(ic);
- } while(ic!=-1);
- fin.close();
- fout.close();
-
-
- }catch(Exception e){
-
- ta.append("Error: Can"t execute "copy" command
- ");
- }
- ta.append("
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
-
- }
- //////////////////// RENAME FILE //////////////////
- else if (commandEnter.startsWith("ren ") || commandEnter.startsWith("ren"))
- {
-
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
-
- try{
- String token=tokenizer.nextToken();
- token=tokenizer.nextToken();
- File oldFile=new File(drive_Name+currentPath+"/"+token);
- if (oldFile.exists()==false) ta.append("Error: File ""+oldFile+"" does"nt exist
- ");
-
- token=tokenizer.nextToken();
- File newFile=new File(drive_Name+currentPath+"/"+token);
- oldFile.renameTo(newFile);
-
- }catch(Exception e){
-
- ta.append("Error: Can"t execute "ren" command
- ");
- }
- ta.append("
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
-
- }
- //////////////////// DELETE FILE //////////////////
- else if (commandEnter.startsWith("kill ") || commandEnter.startsWith("kill"))
- {
-
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- String token=tokenizer.nextToken();
- while(tokenizer.hasMoreTokens()){
-
- try{
- token=tokenizer.nextToken();
- File killFile=new File(drive_Name+currentPath+"/"+token);
-
- if (killFile.exists()==false) ta.append("Error: File ""+killFile+"" does"nt exist
- ");
-
- killFile.delete();
- }catch(Exception e){
- ta.append("Error: Can"t execute "del" command
- ");
- }
- }
- ta.append("
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
-
- }
- //////////////////// MAKE DIRECTORY //////////////
- else if (commandEnter.startsWith("md ") || commandEnter.startsWith("md"))
- {
-
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
-
- while(tokenizer.hasMoreTokens()){
- try{
- String token=tokenizer.nextToken();
- token=tokenizer.nextToken();
- File md=new File(drive_Name+currentPath+"/"+token);
- md.mkdir();
- }catch(Exception e){
- ta.append("Error: Can"t execute "md" command
- ");
- }
- }
- ta.append("
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
-
- }
- //////////////////// EDIT //////////////
- else if (commandEnter.startsWith("edit ") || commandEnter.startsWith("edit"))
- {
-
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- currentContent=ta.getText();
- int ic;
- String fileContent="",currentFile="";
-
- String token=tokenizer.nextToken();
- ta.setText("");
- try{
-
- token=tokenizer.nextToken();
- currentFile=token;
-
- FileInputStream fin =new FileInputStream(drive_Name+currentPath+"/"+token);
-
- do {
- ic=fin.read();
- if (ic!=-1) fileContent=fileContent+(char)ic;
- } while(ic!=-1);
- fin.close();
- ta.append(fileContent);
-
- }catch(Exception e){}
-
- //ta.setText("");
- editOn=true;
- myFrame.setTitle("NetDemo Console - Edit Mode (Type "exit" to quit) - "+currentFile);
- ta.requestFocus();
-
- }
- //////////////////// LOCAL DATE /////////////////
- else if (commandEnter.startsWith("local ") || commandEnter.startsWith("local"))
- {
-
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
-
- String token=tokenizer.nextToken();
- Date date=new Date();
- DateFormat df;
- Locale country=Locale.US;
-
- try{
- token=tokenizer.nextToken();
-
- if (token.equals("-us")) {
- ta.append("United States:
- ");
- country=Locale.US;
- }
- if (token.equals("-uk")) {
- ta.append("United Kingdom:
- ");
- country=Locale.UK;
- }
- if (token.equals("-jp")) {
- ta.append("Japan:
- ");
- country=Locale.JAPAN;
- }
- if (token.equals("-kr")) {
- ta.append("Korea:
- ");
- country=Locale.KOREA;
- }
- if (token.equals("-fr")) {
- ta.append("France:
- ");
- country=Locale.FRANCE;
- }
- if (token.equals("-gr")) {
- ta.append("Germany:
- ");
- country=Locale.GERMANY;
- }
- if (token.equals("-it")) {
- ta.append("Italy:
- ");
- country=Locale.ITALY;
- }
- if (token.equals("-ca")) {
- ta.append("Canada:
- ");
- country=Locale.CANADA;
- }
- if (token.equals("-ch")) {
- ta.append("China:
- ");
- country=Locale.CHINA;
- }
- if (token.equals("-tw")) {
- ta.append("Taiwan:
- ");
- country=Locale.CHINA;
- }
-
- df=DateFormat.getTimeInstance(DateFormat.FULL, country);
- ta.append("Time: "+df.format(date)+"
- ");
- df=DateFormat.getDateInstance(DateFormat.FULL, country);
- ta.append("Date: "+df.format(date)+"
- ");
-
- }catch(Exception e){
- ta.append("Usage: local -us (United States)
- ");
- ta.append(" local -uk (United Kingdom)
- ");
- ta.append(" local -gr (Germany)
- ");
- ta.append(" local -fr (France)
- ");
- ta.append(" local -ca (Canada)
- ");
- ta.append(" local -it (Italy)
- ");
- ta.append(" local -ch (China)
- ");
- ta.append(" local -kr (Korea)
- ");
- ta.append(" local -jp (Japan)
- ");
-
- }
-
- ta.append("
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
-
- }
- ////////////// SORT /////////////////////
- else if (commandEnter.startsWith("sort ") || commandEnter.startsWith("sort"))
- {
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
-
- String token=tokenizer.nextToken();
- TreeSet ts=new TreeSet();
- while(tokenizer.hasMoreTokens()){
- token=tokenizer.nextToken();
-
- try{
- ts.add(token);
- }catch(Exception e){
- ta.append("Error: Can"t execute command "sort"
- ");
- }
-
- }
- ta.append("The sorted list:
- ");
- ta.append(ts+"
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
-
- ////////////// CHECK MEMORY ////////////
- else if (commandEnter.equalsIgnoreCase("memcheck")) {
- Runtime r=Runtime.getRuntime();
- long mem1;
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- ta.append("Total Memory: "+r.totalMemory()+" bytes"+"
- ");
- ta.append("Initial free Memory: "+r.freeMemory()+" bytes"+"
- ");
- r.gc();
- mem1=r.freeMemory();
- ta.append("Free memory after Garbage collection: "+mem1+" bytes
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
-
- ////////////// OS INFORMATION //////////
- else if (commandEnter.equalsIgnoreCase("osinfo")) {
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- String os_arch="",os_name="",os_version="",usr_Name="",usr_Home="";
-
- os_arch=System.getProperty("os.arch");
- os_name=System.getProperty("os.name");
- os_version=System.getProperty("os.version");
- usr_Name=System.getProperty("user.name");
- usr_Home=System.getProperty("user.home");
- ta.append("OS Architecture: "+os_arch+" type
- ");
- ta.append("OS Name: "+os_name);
- if (os_name.equals("Windows 95"))ta.append("(Windows 98/ME)
- ");
- ta.append("OS Version: "+os_version+"
- ");
- ta.append("OS Registered to: "+usr_Name+"
- ");
- ta.append("OS Installation: "+usr_Home+"
- ");
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
- ////////////// QUIT ////////////////////
- else if (commandEnter.equalsIgnoreCase("quit")) {
- System.exit(0);
- }
-
- ////////////// ////////////////////
- else if (commandEnter.equals("")) {
- ta.append("
- ");
- ta.append(currentPath+prompt);
- tf.requestFocus();
- }
- ////////////// PROMPT ////////////////////
- else if (commandEnter.startsWith("prompt ") || commandEnter.startsWith("prompt"))
- {
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- try {
- String token=tokenizer.nextToken();
- token=tokenizer.nextToken();
- prompt=token;
- } catch(Exception e) {t
- a.append("Error: Parameter missing in "prompt"
- Usage: prompt anyword
- ");}
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- }
-
- ////////////// HELP ////////////////////
- else if (commandEnter.equalsIgnoreCase("help") || commandEnter.equalsIgnoreCase("?")) {
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- ta.append("----------|---------------------------|-----------------------------
- ");
- ta.append(" COMMAND | MEANING | EXAMPLE
- ");
- ta.append("----------|---------------------------|-----------------------------
- ");
- ta.append(" ip | Internet Protocol | ip yahoo.com hotmail.com
- ");
- ta.append(" run | Run Program | run calc notepad word prog
- ");
- ta.append(" date | Shows Date | date
- ");
- ta.append(" cls | Clears Screen | cls
- ");
- ta.append(" cd | Changes directory | cd Programs
- ");
- ta.append(" copy | Copy files | copy readme.txt newreadme.txt
- ");
- ta.append(" dir | Shows Directory | dir
- ");
- ta.append(" memcheck | Checks Memory | memcheck
- ");
- ta.append(" prompt | Changes prompt sign | prompt >>>
- ");
- ta.append(" urlinfo | Gives URL information | urlinfo http://www.yahoo.com
- ");
- ta.append(" sort | Sorts given data | sort bad perfect great
- ");
- ta.append(" edit | Goes to Edit mode | edit filename(optional)
- ");
- ta.append(" find | Finds file | find prog.dbm hello.txt
- ");
- ta.append(" kill | Deletes file | kill file1.txt file2.txt
- ");
- ta.append(" save | Saves file in edit mode | save file1 file2 file3
- ");
- ta.append(" local | Shows country Time & Date | local
- ");
- ta.append(" nv | Normal Video | nv
- ");
- ta.append(" bv | Black Video | bv
- ");
- ta.append(" gv | Green Video | gv
- ");
- ta.append(" ov | Orange Video | ov
- ");
- ta.append(" yv | Yellow Video | yv
- ");
- ta.append(" ren | Rename files | ren oldName.txt newName.txt
- ");
- ta.append(" md | Creates new Directory | md newDirectory
- ");
- ta.append(" show | Shows file content | show readme.txt
- ");
- ta.append(" osinfo | OS Information | osinfo
- ");
- ta.append(" exit | Exits from Edit Mode | exit
- ");
- ta.append(" help | Shows help information | help
- ");
- ta.append(" ? | Shows help information | ?
- ");
- ta.append(" whois | Gives information of site | whois internic.net dotcom.com
- ");
- ta.append(" quit | Quits NetDemo / Edit mode | quit
- ");
-
- ta.append(currentPath+prompt);
- tf.requestFocus();
- }
- ////////////// ERROR ////////////////////
- else
- {
- ta.setEditable(true);
- ta.append(commandEnter+"
- ");
- String temp=currentPath+"/"+commandEnter;
- String temp2=temp.replace(""," ");
- StringTokenizer st=new StringTokenizer(temp2);
- String temp3=st.nextToken();
- String temp4=st.nextToken();
- temp2=temp3+temp4;
- //System.out.println(temp2);
- try {
- Runtime r=Runtime.getRuntime();
- Process p=null;
- p=r.exec(temp2);
-
- }catch(Exception e){ta.append("Error: Illegal command call
- ");}
- ta.append(currentPath+prompt);
- //ta.setEditable(false);
- tf.requestFocus();
- }
-
- }
- }
- public static void main(String args[]) throws Exception{
- myFrame=new Frame("Molecule (NetDemo Console) - Type "help" or "?" for Help");
- NetDemo nd=new NetDemo();
- myFrame.add(nd);
- myFrame.setSize(600,400);
- myFrame.setLocation(200,100);
- myFrame.pack();
- myFrame.setResizable(false);
- myFrame.show();
- myFrame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent we)
- {System.exit(0);}
- });
- }
- }
复制代码
源码下载:http://file.javaxxz.com/2014/10/2/082125547.zip |
|