Java寫的一個記事本工具

     近日整理電腦發現了不少大學與研究生時期的軟件作品,先發布出來了,一是記錄一下十年的程序生涯;二是對於有需要的人可以利用之。

     先發佈一個記事本程序,這個記事本支持HTTP下載內容的顯示。

     運行截圖如下:


   

源代碼如下:

     Liunotepad.java

/*記事本的製作:
 仿Window notepad;
 作者:my2005lb;
 時間:2005/2/21;
 功能:<1>打開文件;
       <2>保存文件;
       <3>全選,剪切,複製,粘貼;
       <4>加入時間,查找,替換;
       <5>網絡HTTP/FTP服務;
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.util.Date;
import java.awt.List.*;
import java.lang.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
//import javax.swing.*;
class mydatetime{//日期mydatetime類
	String year;
	String month;
	String day;
	String datetime;
	Date date;
	String week;
   	mydatetime()
	{
	    date=new Date();
	    year=this.getyear();
	    month=this.getmonth();
	    day=this.getday();
	    datetime=this.getdatetime();
	    week=this.getWeek();
	}
	String getyear()
	{
		String temp;
		int index;
		index=this.date.toString().lastIndexOf(" ");
		temp=this.date.toString().substring(index,date.toString().length());
		return temp;
	}
	String getmonth()
	{
		String temp;
		temp=this.date.toString().substring(4,7);
		if(temp.equals("Feb"))
		 return "2";
		else if(temp.equals("Apr"))
		 return "4";
	    else if(temp.equals("May"))
		 return "5";
		else if(temp.equals("Jun"))
		 return "6"; 	
		else if(temp.equals("Jul"))
		 return "7";   
		else if(temp.equals("Aug"))
		 return "8"; 
		else if(temp.equals("Sep"))
		 return "9"; 
		else if(temp.equals("Oct"))
		 return "10"; 
		else if(temp.equals("Nov"))
		 return "11"; 
		else if(temp.equals("Dec"))
		 return "12"; 
		else
		 return temp; 
		 
	}
	String getday()
	{
		String temp;
		temp=date.toString().substring(8,10);
		return temp;
		
	}
	String getdatetime()
	{
		String temp;
		temp=date.toString().substring(11,19); 
	    return temp;
	}
	String getWeek()
	{
		String temp=this.date.toString().substring(0,3);
		if(temp.equals("Mon"))
		{
			return "星期一";
		}
		else if(temp.equals("Tue"))
		{
			return "星期二";
		}
		else if(temp.equals("Wed"))
		{
			return "星期三";
		}
		else if(temp.equals("Thu"))
		{
			return "星期四";
		}
		else if(temp.equals("Fri"))
		{
			return "星期五";
		}
		else if(temp.equals("Sat"))
		{
			return "星期六";
		}
		else if(temp.equals("Sun"))
		{
			return "星期七";
		}
		else
		 return "";
	}
}
/*class Ftp_Send extends Frame implements ActionListener {
          FileDialog File_Send_Dialog;
          Socket File_Send_Socket;
          Button Send;
          Button Cancle;
          
          Ftp_Send()
          {
             File_Send_Dialog=new FileDialog(this,"文件發送選擇框",FileDialog.LOAD);
             File_Send_Socket=new Socket("127.0.0.1",2223);
             File file=new File(File_Send.getDirectory(),File_Send.getFile());
             FileOutputStream File_Send=new FileOutputStream(file);
             
          }
}*/
class Self_Font extends Frame implements ActionListener,ItemListener{
      Button Confirmation;
      Button Cancle;
      Label Font_Name_Label;
      Label Font_Style_Label;
      Label Font_Size_Label;
      List Font_Name_List;
      List Font_Style_List;
      List Font_Size_List;
      TextArea Example;
      Liunotepad SelfFont;
      String Font_Name;
      int Font_Style;
      int Font_Size;
      Self_Font(Liunotepad SelfFont)
      {
      	this.setTitle("字體設置");
      	Confirmation=new Button("確定");
      	Cancle=new Button("取消");
      	Font_Name_Label=new Label("字體");
      	Font_Style_Label=new Label("字形");
      	Font_Size_Label=new Label("字號"); 
      	this.Font_Name="Courier";
      	this.Font_Style=Font.BOLD;
      	this.Font_Size=18;
      	Font_Name_List=new List();
      	Font_Style_List=new List();
        Font_Size_List=new List();
        this.setBackground(Color.CYAN);
        Example=new TextArea("文字測試",3,25);
        Example.setEnabled(false);
        this.SelfFont=SelfFont;
        this.setLayout(new FlowLayout());
        this.add(Font_Name_Label);
        this.add(Font_Name_List);
        this.add(Font_Style_Label);
        this.add(Font_Style_List);
        this.add(Font_Size_Label);
        this.add(Font_Size_List);
        this.add(Example,FlowLayout.LEFT);
        this.add(Confirmation);
        this.add(Cancle);
      /*  Font_Name_Label.setBounds(5,5,25,20);
        Font_Name_List.setBounds(5,25,40,60);
        Font_Style_Label.setBounds(25,5,45,20);
        Font_Style_List.setBounds(25,25,65,60);
        Font_Size_Label.setBounds(45,5,65,20);
        Font_Size_List.setBounds(45,25,85,60);
        Confirmation.setBounds(100,20,120,35);
        Cancle.setBounds(100,40,120,55);
        Example.setBounds(5,75,60,120);
        */
        Font_Name_List.add("Courier");
        Font_Name_List.add("Roman");
        Font_Name_List.add("隸書");
        Font_Name_List.add("宋體");
        Font_Name_List.add("新宋體");
        Font_Name_List.add("幼圓");
        Font_Name_List.add("楷體_GB2312");
        Font_Name_List.add("華文宋體");
        Font_Name_List.add("仿宋_GB2312");
        Font_Name_List.add("黑體");
        Font_Name_List.add("Verdana");
        Font_Style_List.add("常規");
        Font_Style_List.add("粗體");
        Font_Style_List.add("斜體");
        Font_Style_List.add("粗斜體");
        Font_Size_List.add("8號");
        Font_Size_List.add("12號");
        Font_Size_List.add("20號");
        Font_Size_List.add("24號");
        Font_Size_List.add("30號");
        Font_Size_List.add("40號");
        this.pack();
        this.setVisible(true);
        Font_Name_List.addItemListener(this);
        Font_Style_List.addItemListener(this);
        Font_Size_List.addItemListener(this);
        Confirmation.addActionListener(this);
        Cancle.addActionListener(this);
        this.addWindowListener(new WindowAdapter(){
           public void windowClosing(WindowEvent e)
           {
           	 setVisible(false);
           }
        });

      }
      public void actionPerformed(ActionEvent actionevent)
      {
      	if(actionevent.getSource()==Confirmation)
      	{
      	try{
      		    this.SelfFont.txt1.setFont(new Font(this.Font_Name,this.Font_Style,this.Font_Size));
      	}catch(Exception exception)
      	{}
      	finally
        	{
      	    	this.setVisible(false);
      	    }
      		
      	}
       else if(actionevent.getSource()==Cancle)
      	{
      		this.setVisible(false);
      	}
      }
    public void itemStateChanged(ItemEvent e)
    {
     try{	
    	 if(e.getSource()==Font_Name_List)
        	{
    	    	this.Font_Name=this.Font_Name_List.getSelectedItem();
    	        this.Example.setFont(new Font(this.Font_Name,this.Font_Style,this.Font_Size));
    	    }
    	 else if(e.getSource()==Font_Style_List)
    	    {
    	    	if(this.Font_Style_List.getSelectedItem().equals("粗體")) 
      		       this.Font_Style=Font.BOLD;
      		    else if(this.Font_Style_List.getSelectedItem().equals("斜體")) 
      		       this.Font_Style=Font.ITALIC;
      	     	else if(this.Font_Style_List.getSelectedItem().equals("粗斜體")) 
      		       this.Font_Style=Font.PLAIN;
      		    else
      		       this.Font_Style=0; 
      		    this.Example.setFont(new Font(this.Font_Name,this.Font_Style,this.Font_Size));
    	      
    	    }
    	 else if(e.getSource()==Font_Size_List)
    	    {
    	    	if(this.Font_Size_List.getSelectedItem().equals("12號"))
      		       Font_Size=12;
      	    	else if(this.Font_Size_List.getSelectedItem().equals("8號"))
      		       Font_Size=8;
      		    else if(this.Font_Size_List.getSelectedItem().equals("20號"))
      		       Font_Size=20;
      		    else if(this.Font_Size_List.getSelectedItem().equals("24號"))
      		       Font_Size=24;
      		    else if(this.Font_Size_List.getSelectedItem().equals("30號"))
      		       Font_Size=30;
      		    else if(this.Font_Size_List.getSelectedItem().equals("40號"))
      		       Font_Size=40;
      		    else 
      		       Font_Size=18;  
      		    this.Example.setFont(new Font(this.Font_Name,this.Font_Style,this.Font_Size));
    	      
    	    }
    	}catch(Exception exception)
    	{}    
    	
    }  
}
class Self_Color extends Frame implements ActionListener,ItemListener{
	List Color_List;
	Label Color_Label;
	Button Confirmation;
	Button Cancle;
	TextField Example;
	Liunotepad SelfColor; 
	Color Example_Color;
	Self_Color(Liunotepad SelfColor)
	{
		this.SelfColor=SelfColor;
		this.setTitle("顏色選擇");
		Color_List=new List();
		Color_Label=new Label("顏色種類");
		Confirmation=new Button("確定");
		Cancle=new Button("取消");
		Example=new TextField("文字測試",7);
		Example.setEnabled(false);
		Color_List.add("紅色");
		Color_List.add("黑色");
		Color_List.add("黃色");
		Color_List.add("藍色");
		Color_List.add("紫色");
		Color_List.add("綠色");
		Color_List.add("灰色");
		this.setLayout(new FlowLayout());
		this.add(Color_Label);
		this.add(Color_List);
		this.add(Example);
		this.add(Confirmation);
		this.add(Cancle);
		this.pack();
		this.setVisible(true);
		Confirmation.addActionListener(this);
		Cancle.addActionListener(this);
		Color_List.addItemListener(this);
		this.addWindowListener(new WindowAdapter(){
		public void windowClosing(WindowEvent e)
		{
			setVisible(false);
		}
		});
	}
	public void actionPerformed(ActionEvent actionevent)
	{
		if(actionevent.getSource()==Confirmation)
		{
			if(Color_List.getSelectedItem().equals(""))
			  this.Example_Color=Color.BLACK;
			this.SelfColor.txt1.setForeground(this.Example_Color);
			this.setVisible(false);
		}
		else if(actionevent.getSource()==Cancle)
		{
			this.setVisible(false);
		}
	}
	public void itemStateChanged(ItemEvent itemevent)
	{
		if(itemevent.getSource()==Color_List)
		{
			if(Color_List.getSelectedItem().equals("紅色"))
			   this.Example_Color=Color.red;
			else if(Color_List.getSelectedItem().equals("黑色"))
			   this.Example_Color=Color.black;   
		    else if(Color_List.getSelectedItem().equals("黃色"))
			   this.Example_Color=Color.yellow;
			else if(Color_List.getSelectedItem().equals("藍色"))
			   this.Example_Color=Color.blue; 
			else if(Color_List.getSelectedItem().equals("紫色"))
			   this.Example_Color=Color.cyan; 
			else if(Color_List.getSelectedItem().equals("綠色"))
			   this.Example_Color=Color.green; 
			else if(Color_List.getSelectedItem().equals("灰色"))
			   this.Example_Color=Color.gray;     
			this.Example.setForeground(this.Example_Color);           
		}
	}
}
class ChangeInto extends Frame implements ActionListener{
      Button Change;
      Button Cancle;
      TextField first;
      TextField second;
      Label First;
      Label Second;
      Liunotepad liunotepad;
      ChangeInto(Liunotepad liunotepad)
      {
      	this.setTitle("替換");
      	Change=new Button("替換");
      	Cancle=new Button("取消");
      	First=new Label("要替換的字");
      	Second=new Label("要替換用的字");
      	this.liunotepad=liunotepad;
      	first=new TextField(20);
      	second=new TextField(20);
      	this.setLayout(new FlowLayout());
      	this.add(First);
      	this.add(first);
      	this.add(Second);
      	this.add(second);
      	this.add(Change);
      	this.add(Cancle);
      /*First.setBounds(5,5,30,20);
      	first.setBounds(40,5,65,20);
      	Second.setBounds(5,30,30,45);
      	second.setBounds(40,30,65,45);
      	Change.setBounds(15,55,30,65);
      	Cancle.setBounds(40,55,55,70);*/
      	Change.addActionListener(this);
      	Cancle.addActionListener(this);
      	this.setVisible(true);
      	pack();
      	this.addWindowListener(new WindowAdapter(){
      	  public void windowClosing(WindowEvent windowevent)
      	  {
      	  	setVisible(false);
      	  }
      	});
      }    
      public void actionPerformed(ActionEvent actionevent)
      {
      	if(actionevent.getSource()==Change)
      	{
      		if(first.getText()!=""&&second.getText()!=""&&!first.getText().equals(second.getText()))
      		{try{
      			String str1=first.getText();
      			String str2=second.getText();
      			String temp=this.liunotepad.txt1.getText();
      			this.liunotepad.txt1.setText(temp.replaceAll(str1,str2));
      		   }catch(Exception exception)
      		   {}
      		}
      		this.setVisible(false);
      	}
      	else if(actionevent.getSource()==Cancle)
      	{
      		this.setVisible(false);
      	}
      }
}
class Find extends Frame implements ActionListener{
      Button Find_String;
      Button Cancle;
      TextField Input;
      Label Tip_Information;
      Liunotepad liunotepad;
      Find(Liunotepad liunotepad)
      {
      	Find_String=new Button("查找");
      	this.liunotepad=liunotepad;
      	Cancle=new Button("取消");
      	Input=new TextField(20);
      	Tip_Information=new Label("請輸入要查找的信息:");
      	this.setTitle("查找");
      	this.setBackground(Color.BLUE);
      	this.setLayout(new FlowLayout());
      	this.add(Tip_Information);
      	this.add(Input);
      	this.add(Find_String);
      	this.add(Cancle);
      	Find_String.addActionListener(this);
      	Cancle.addActionListener(this);
      	this.pack();
      	this.setVisible(true);
      	this.addWindowListener(new WindowAdapter(){
      		public void windowClosing(WindowEvent windowevent)
      		{
      			setVisible(false);
      		}});
      }
      public void actionPerformed(ActionEvent e)
      {
      	 if(e.getSource()==Find_String)
      	 {
      	 	if(this.Input.getText()!="")
      	 	{
     	 	 String temp=this.liunotepad.txt1.getText();
      	 	 int code=temp.indexOf(this.Input.getText());
      	 	 System.out.println(code);
      	 	 this.liunotepad.txt1.select(code,code+this.Input.getText().length());
      	 	 System.out.println(code+this.Input.getText().length());
      	 	}
      	 	this.setVisible(false);
         }
         else if(e.getSource()==Cancle)
         {
         	this.setVisible(false);
         }
      }
}
class Tip extends Frame implements ActionListener{
      Button Confirmation;
      Button Cancle;
      Button Ignore;
      Label Tip_Information;
      Liunotepad liunotepad;
      Tip(Liunotepad liunotepad)
      {
      	this.liunotepad=liunotepad;
      	Confirmation=new Button("是");
      	Cancle=new Button("否");
      	Ignore=new Button("不理");
      	Tip_Information=new Label("是否保存");
      	this.setBackground(Color.GREEN);
      	this.setTitle("小提示!");
      	this.setLayout(new FlowLayout());
      	this.add(Tip_Information);
      	this.add(Confirmation);
      	this.add(Cancle);
      	this.add(Ignore);
      	this.addWindowListener(new WindowAdapter(){
      	 public void windowClosing(WindowEvent windowevent)
      	 {
      	 	setVisible(false);
      	 }
      	});
      	this.pack();
      	this.setVisible(true);
      	Confirmation.addActionListener(this);
      	Cancle.addActionListener(this);
      	Ignore.addActionListener(this);
      }
      public void actionPerformed(ActionEvent actionevent)
      {
      	if(actionevent.getSource()==Confirmation)
      	{
      		//this.liunotepad.itemsave.getAccessibleContext();
      	}
      	else if(actionevent.getSource()==Cancle)
      	{
      		System.exit(0);
      	}
      	else if(actionevent.getSource()==Ignore)
      	{
      		this.setVisible(false);
      	}
      }
}
class cls extends WindowAdapter{//關閉cls類
 public void windowClosing(WindowEvent e)
 {
 	 System.exit(0);
 }
}
class NetworkServer extends Frame implements ActionListener{//網絡服務類NetworkServer
     Button confirmation;
     Button cancle;
     Label  content;
     TextField receive;
     String protocol;
     Liunotepad liunotepad;
     NetworkServer(String protocol,Liunotepad liunotepad)
     {
     	this.setTitle("網絡服務");
     	confirmation=new Button("確定");
     	cancle=new Button("取消");
     	content=new Label("請輸入IP地址");
     	receive=new TextField();
     	this.liunotepad=liunotepad;
     	this.protocol=protocol;
     	this.setLayout(new GridLayout());
     	this.add(content);
     	this.add(receive);
     	this.add(confirmation);
     	this.add(cancle);
     	this.pack();
        this.setVisible(true);
     	confirmation.addActionListener(this);
     	cancle.addActionListener(this);
     	this.addWindowListener(new WindowAdapter(){
     		public void windowClosing(WindowEvent windowevent)
     		{
     			setVisible(false);
     		}
     		                                      });
     }
     public void actionPerformed(ActionEvent e)
     {
     	if(e.getSource()==confirmation)
     	
     	{
     	 try{
     	 	   String s;
     	 	   s=this.protocol;
     	 	   s+=receive.getText();
     		   URL url=new URL(s);
			   DataInputStream ds=new DataInputStream(url.openStream());
			   this.liunotepad.txt1.setText("這是"+s+"網址的全部源程序代碼\n");
			   while(ds.readLine()!=null)
			   {
			   	 this.liunotepad.txt1.append(ds.readLine()+"\n");
			   }
			   this.setVisible(false);
			 }catch(Exception exception)
			 {}  
     	}
     	else if(e.getSource()==cancle)
     	{
     		this.setVisible(false);
     	}
     }
}
class helpindex extends Frame implements ActionListener{
 Button b;
 TextArea information;
 helpindex()
 {
  String author;
  author="作者:my2005lb"+"\n"+"聯繫地址:XXX"+"\n"+"聯繫電話:XXX";	
  this.setLayout(new BorderLayout());	
  information=new TextArea(author);
  information.setFont(new Font("Courier",Font.BOLD,18));
  b=new Button("關閉");	
  this.setTitle("記事本");
  this.setBackground(Color.BLUE);
  this.setSize(100,100);
  this.add(information,BorderLayout.CENTER);
  this.add(b,BorderLayout.NORTH);
  this.information.setEnabled(false);
  this.pack();
  this.setVisible(true); 
  b.addActionListener(this);
  this.addWindowListener(new WindowAdapter(){
  	public void windowClosing(WindowEvent windowevent)
  	{
  		setVisible(false);
  		}});
 }
 void disvisible()
 {
   this.dispose();
 }
 public void actionPerformed(ActionEvent ac)
 {
 	if(ac.getSource()==b)
 	{
 		this.setVisible(false);
 		disvisible();
 		
 	}
 }
}
public class Liunotepad extends Frame implements ActionListener,ItemListener
{
	MenuBar mnub;
	Menu mnu1,mnu2,mnu3,mnu31,mnu4,network,Ftp;
	MenuItem item1,item2,item3,item4,item5,item6,item7,item71,item72,item9,itemsave;
	MenuItem index,content;
	MenuItem selectalltext,find,changeinto;
	MenuItem http,ftp,Ftp_Send,Ftp_Receive,Ftp_Login;
	//MenuItem font_color_y,font_color_r,font_color_b;
	CheckboxMenuItem item8;
	MenuShortcut stcte=new MenuShortcut(KeyEvent.VK_E);
	MenuShortcut stctn=new MenuShortcut(KeyEvent.VK_N);
	Clipboard clp=null;
	TextArea txt1;
	FileDialog open,save;
	Scrollbar scrollbar;
	ScrollPane scrollpane;
	Image First_Image;
	Liunotepad()
	{
	    super("記事本");
		this.setVisible(true);
		this.setBackground(Color.blue);
		this.setResizable(true);
        setLayout(new FlowLayout());
        scrollpane=new ScrollPane();
        scrollbar=new Scrollbar();
		setBounds(10,10,100,60);
		txt1=new TextArea();
		this.txt1.setFont(new Font("Courier",Font.BOLD,18));
		this.scrollpane.add(scrollbar);
		this.scrollpane.add(txt1);
		this.scrollpane.setSize(1000,680);
		mnub=new MenuBar();
		this.setMenuBar(mnub);
		open=new FileDialog(this,"打開",FileDialog.LOAD);
		save=new FileDialog(this,"保存",FileDialog.SAVE);
		First_Image=this.getIconImage();
		mnu1=new Menu("文件");
		mnu2=new Menu("編輯");
		mnu3=new Menu("插入");
		mnu31=new Menu("文本框");
		network=new Menu("網絡服務");
		Ftp=new Menu("FTP服務");
		http=new MenuItem("HTTP服務");
		ftp=new MenuItem("FTP連接服務");
		Ftp_Send=new MenuItem("上載文件");
		Ftp_Receive=new MenuItem("下載文件");
		Ftp_Login=new MenuItem("身份登陸");
		selectalltext=new MenuItem("全選(ctrl+A)",new MenuShortcut(KeyEvent.VK_A)); 
		item1=new MenuItem("新建(New)",stctn);
		item2=new MenuItem("打開(Open)",new MenuShortcut(KeyEvent.VK_O));
		itemsave=new MenuItem("保存(Save)",new MenuShortcut(KeyEvent.VK_S));
		item3=new MenuItem("退出(Exit)");
		item3.setShortcut(stcte);
		item4=new MenuItem("複製(Ctrl+C)");
		item5=new MenuItem("剪切(Ctrl+X)");
		item6=new MenuItem("粘貼(Ctrl+V)");
		find=new MenuItem("查找(Ctrl+F)",new MenuShortcut(KeyEvent.VK_F));
		changeinto=new MenuItem("替換(Ctrl+I)",new MenuShortcut(KeyEvent.VK_I));
		item71=new MenuItem("字體");
		item72=new MenuItem("顏色");
		item8=new CheckboxMenuItem("圖片");
		item9=new MenuItem("時間");
		mnu4=new Menu("幫助");
		index=new MenuItem("自我介紹");
		content=new MenuItem("幫助內容");
		mnub.add(mnu1);
		mnub.add(mnu2);
		mnub.add(mnu3);
		mnub.add(network);
		mnub.add(mnu4);
		mnu3.add(mnu31);
		mnu1.add(item1);
		mnu1.addSeparator();
		mnu1.add(item2);
		mnu1.addSeparator();
		mnu1.add(itemsave);
		mnu1.addSeparator();
		mnu1.add(item3);
		mnu2.add(selectalltext);
		mnu2.addSeparator();
	    mnu2.add(item4);
		mnu2.addSeparator();
		mnu2.add(item5);
		mnu2.addSeparator();
		mnu2.add(item6);
		mnu2.addSeparator();
		mnu2.add(changeinto);
		mnu2.addSeparator();
		mnu2.add(find);
		mnu31.add(item71);
		mnu31.addSeparator();
		mnu31.add(item72);
		mnu3.addSeparator();
		mnu3.add(item8);
		mnu3.addSeparator();
		mnu3.add(item9);
		network.add(http);
		network.addSeparator();
		network.add(Ftp);
		Ftp.add(ftp);
		Ftp.addSeparator();
		Ftp.add(Ftp_Send);
		Ftp.addSeparator();
		Ftp.add(Ftp_Receive);
		Ftp.addSeparator();
		Ftp.add(Ftp_Login);
		Ftp.addSeparator();
		mnu4.add(index);
		mnu4.addSeparator();
		mnu4.add(content);
		add(scrollpane);
		pack();
		clp=getToolkit().getSystemClipboard();
		item1.addActionListener(this);
		item2.addActionListener(this);
		item3.addActionListener(this);
		item4.addActionListener(this);
		item5.addActionListener(this);
		item6.addActionListener(this);
		item71.addActionListener(this);
		item72.addActionListener(this);
		item8.addItemListener(this);
		changeinto.addActionListener(this);
		find.addActionListener(this);
		item1.addActionListener(this);
		selectalltext.addActionListener(this);
		item9.addActionListener(this);
		itemsave.addActionListener(this);
		index.addActionListener(this);
		content.addActionListener(this);
		http.addActionListener(this);
		ftp.addActionListener(this);
		Ftp_Login.addActionListener(this);
		Ftp_Send.addActionListener(this);
		Ftp_Receive.addActionListener(this);
		addWindowListener(new cls());
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==item1)
		{
			txt1.setText("");
		}
		else if(e.getSource()==item2)
		{
			String str;
			this.open.setVisible(true);
			try{
				File file=new File(open.getDirectory(),open.getFile());
				FileReader filereader=new FileReader(file);
				BufferedReader br=new BufferedReader(filereader);
				this.txt1.setText("");
				while((str=br.readLine())!=null)
				{
					this.txt1.append(str+"\n");
				}
				filereader.close();
			}catch(Exception fe)
			{}
		}
		else if(e.getSource()==itemsave)
		{
			save.setVisible(true);
			try{
				File file=new File(save.getDirectory(),save.getFile());
				FileWriter filewriter=new FileWriter(file);
				BufferedWriter bw=new BufferedWriter(filewriter);
				String temp=this.txt1.getText();
				bw.write(temp,0,temp.length());
				bw.flush();
				bw.close();
				
			}catch(Exception fge)
			{}
		}
		else if(e.getSource()==item3)
		{
			if(this.txt1.getText()!="")
			{
				Tip tip=new Tip(this);
			}
			else
			 System.exit(0);
		}
		else if(e.getSource()==item4)
		{
		 String str=txt1.getSelectedText();
		 StringSelection txt=new StringSelection(str);
		 clp.setContents(txt,null);	
		}
		else if(e.getSource()==item5)
		{
		 String str=txt1.getSelectedText();
		 StringSelection txt=new StringSelection(str);
		 clp.setContents(txt,null);	
		 int start=txt1.getSelectionStart();
		 int end=txt1.getSelectionEnd();
		 txt1.replaceRange("",start,end);	
		}	
		else if(e.getSource()==item6)
		{
			Transferable cnt=clp.getContents(this);
			DataFlavor flv=DataFlavor.stringFlavor;
			if(cnt.isDataFlavorSupported(flv))
		     try{
		     	String str;
		     	str=(String)cnt.getTransferData(flv);
		     	txt1.append(str);
		        }catch(Exception ei){}
		 }
		else if(e.getSource()==selectalltext)
		{
			this.txt1.selectAll();
		} 
		else if(e.getSource()==item71)
		{
			Self_Font myFont=new Self_Font(this);
		}
		else if(e.getSource()==Ftp_Send)
		{}
		else if(e.getSource()==Ftp_Receive)
		{}
		else if(e.getSource()==Ftp_Login)
		{}
		else if(e.getSource()==item72)
		{
			Self_Color mycolor=new Self_Color(this);
		}		
		else if(e.getSource()==item9)
		{
			mydatetime t=new mydatetime();
			this.txt1.append("\n今年是"+t.year+"年"+t.month+"月"+t.day+"日現在時間 "+t.datetime+" "+t.week);
		}		
            
	    else if(e.getSource()==index)
		{
		   	helpindex d=new helpindex();
		}
		else if(e.getSource()==content)
		{
			try{
				 Runtime runtime=Runtime.getRuntime();
				 runtime.exec("table.exe");
			   }
			   catch(Exception exception)
			   {
			   	 System.out.println("打開類型出錯");
			   }
		}
		else if(e.getSource()==changeinto)
		{
			ChangeInto cot=new ChangeInto(this);
		}
		else if(e.getSource()==find)
		{
			Find _find=new Find(this);
		}
		else if(e.getSource()==http)
		{
		  NetworkServer http_net=new NetworkServer("http://",this);
		  //this.txt1.setText(http_net.temp);	
		}
		else if(e.getSource()==ftp)
		{
			NetworkServer http_net=new NetworkServer("ftp://",this);
			//System.out.println("這是HTTP://LOCALHOST");
			//System.out.println(http_net.temp); 
		    //this.txt1.setText(http_net.temp);	
		}
	}
	public void itemStateChanged(ItemEvent e)
	{
		
		if(item8.getState()==true)
		{ 	
		try{
		 Toolkit toolkit=getToolkit();	
		 Image image=toolkit.getImage("liunotepad.ico");
		 this.setIconImage(image);
		   }catch(Exception exception)
		   {
		   	System.out.println("找不到圖像文件");
		   }
		}
		else
		 this.setIconImage(First_Image);
	}
   public static void main(String args[])
   {
   	Liunotepad s=new Liunotepad();
   } 
}			

manifest文件

Manifest-Version: 1.0
Main-Class: Liunotepad.class
Create-By: 1.2.2(sun Microsystems Inc.);



發佈了83 篇原創文章 · 獲贊 5 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章