最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2015年04月16日 14:41:12   作者:司青  
這篇文章主要介紹了Java實(shí)現(xiàn)的簡(jiǎn)易記事本,較為詳細(xì)的分析了基于java實(shí)現(xiàn)記事本程序的完整過(guò)程,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Java實(shí)現(xiàn)的簡(jiǎ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ì)有所幫助。

相關(guān)文章

最新評(píng)論

阜宁县| 会同县| 酉阳| 康乐县| 靖江市| 卓尼县| 长春市| 法库县| 兴业县| 民丰县| 锦州市| 确山县| 东源县| 盐亭县| 英德市| 封丘县| 广西| 如东县| 准格尔旗| 赞皇县| 平凉市| 三台县| 赣州市| 海南省| 新田县| 长春市| 天全县| 图片| 江西省| 凤山县| 云和县| 宜兰市| 中阳县| 吴桥县| 大英县| 巴林左旗| 合水县| 铁岭市| 闻喜县| 永靖县| 玉环县|