国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

Java實(shí)現(xiàn)的簡易記事本

2019-11-26 15:13:05
字體:
供稿:網(wǎng)友

本文實(shí)例講述了Java實(shí)現(xiàn)的簡易記事本。分享給大家供大家參考。具體如下:

感覺這個(gè)沒有自己以前用Windows API寫的好看了。。。

JDK Version : 1.7.0

效果如下圖所示:

源代碼如下:

import java.io.*; import java.awt.*; import java.awt.event.*; /**  * The Main Window  * @author Neo Smith  */ class PadFrame extends Frame {   private MenuBar mb;   private Menu menuFile;   private Menu menuEdit;   private MenuItem[] miFile;   private TextArea ta;   final private Frame frame = this;   /**    * The inner class    * Message Handle    */   class EventExit implements ActionListener   {     public void actionPerformed(ActionEvent e)    {       System.exit(0);     }   }   class SystemExit extends WindowAdapter   {     public void windowClosing(WindowEvent e)    {       System.exit(0);     }   }   class EventMenuClose implements ActionListener  {     public void actionPerformed(ActionEvent e)    {       ta.setText(null);     }   }   class EventOpenFile implements ActionListener  {     public void actionPerformed(ActionEvent e)     {       //Create the OpenFile Dialog       FileDialog dlg = new FileDialog(frame,"Open Files",FileDialog.LOAD);      dlg.show();              String strPath;       if((strPath = dlg.getDirectory()) != null)       {         //get the full path of the selected file        strPath += dlg.getFile();                  //open the file         try         {           FileInputStream fis = new FileInputStream(strPath);           BufferedInputStream bis = new BufferedInputStream(fis);           byte[] buf = new byte[3000];           int len = bis.read(buf);                      ta.append(new String(buf,0,len));           bis.close();         }         catch(Exception ex)         {           ex.printStackTrace();         }       }     }   }   /**    * Construction Method    * Adding Menu and TextArea components    * @param strTitle    */   public PadFrame(String strTitle)   {     super(strTitle);     this.setLocation(400,200);     this.setSize(900, 630);          //Create the Menu Bar     mb = new MenuBar();     menuFile = new Menu("File");     menuEdit = new Menu("Edit");     miFile = new MenuItem[]{new MenuItem("Open"),new MenuItem("Close"),new MenuItem("Exit")};     this.setMenuBar(mb);     mb.add(menuFile);     mb.add(menuEdit);     for(int i = 0 ; i < miFile.length ; ++i)     {       menuFile.add(miFile[i]);     }     //Add event handle     setMenuEventHandle(new EventExit(),"File",2);     setMenuEventHandle(new EventOpenFile(),"File",0);     setMenuEventHandle(new EventMenuClose(),"File",1);     this.addWindowListener(new SystemExit());          //add the TextArea component     ta = new TextArea(30,30);     this.add(ta);   }   public void setMenuEventHandle(ActionListener al,String strMenu,int index)   {     if(strMenu == "File")     {       miFile[index].addActionListener(al);     }   }   public int getMenuItemAmount(String strMenu)   {     if("File" == strMenu)     {       return miFile.length;     }          return -1;   }   public static void main(String[] args)   {     PadFrame f = new PadFrame("NotePad");     f.show();   } }

希望本文所述對(duì)大家的java程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 平罗县| 若羌县| 应城市| 阿勒泰市| 西乌珠穆沁旗| 叶城县| 南澳县| 兖州市| 雅江县| 偏关县| 房产| 同江市| 塔河县| 安徽省| 女性| 新邵县| 蓬安县| 舒兰市| 荃湾区| 宁国市| 柯坪县| 靖边县| 林芝县| 安吉县| 嘉禾县| 娱乐| 军事| 城步| 淳化县| 雷山县| 墨脱县| 西林县| 平和县| 山东| 什邡市| 永城市| 万山特区| 大厂| 海淀区| 鄱阳县| 庆元县|