2008年12月23日

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Toolkit;

public class FileIO extends WindowAdapter implements ActionListener
{
 JFrame jf;
    JButton jb,jb1;
    JTextArea ta;
    String filename,copy,paste,cut;
    JPanel jp;
    JMenu jmb,jmb2;
    JMenuItem _fm,_fm1,_fm2,_fm3,_fm4,_fe1,_fe2,_fe3,_fe4;
    JMenuBar JMENU;
    JScrollPane jsp;
    JLabel jl;

    public static void main (String[] argv)
    {
  new FileIO();
    }
    public FileIO()
    {
  //设置菜单栏和菜单的内容
  jp = new JPanel();
        jl = new JLabel("伟华记事本V1.0");
      JMENU = new JMenuBar();
      ta = new JTextArea();
      jf = new JFrame();
      jsp = new JScrollPane(ta);
      jf.addWindowListener(this);
      jmb = new JMenu("文件");
      jmb2 = new JMenu("编辑");
      _fm1 = new JMenuItem("打开");
      _fm1.addActionListener(this);
      _fm2 = new JMenuItem("储存");
      _fm2.addActionListener(this);
      _fm4 = new JMenuItem("另存为");
      _fm4.addActionListener(this);
      _fm3 = new JMenuItem("关闭");
      _fm3.addActionListener(this);
      _fm = new JMenuItem("新建");
      _fm.addActionListener(this);

      _fe1 = new JMenuItem("复制");
      _fe1.addActionListener(this);
      _fe2 = new JMenuItem("粘贴");
      _fe2.addActionListener(this);
      _fe3 = new JMenuItem("剪切");
      _fe3.addActionListener(this);
      _fe4 = new JMenuItem("作者");
      _fe4.addActionListener(this);
      jf.setJMenuBar(JMENU);
      jf.setTitle("记事本");

      jmb.add(_fm);
      jmb.addSeparator();
      jmb.add(_fm1);
      jmb.addSeparator();
        jmb.add(_fm2);
      jmb.addSeparator();
      jmb.add(_fm4);
      jmb.addSeparator();
      jmb.add(_fm3);
      jmb2.add(_fe1);
      jmb2.addSeparator();
      jmb2.add(_fe2);
      jmb2.addSeparator();
      jmb2.add(_fe3);
      jmb2.addSeparator();
      jmb2.add(_fe4);

      JMENU.add(jmb);
      JMENU.add(jmb2);

 

      jb = new JButton("保存");
      jb.addActionListener(this);
      jb1 = new JButton("关闭");
      jb1.addActionListener(this);
      jp.add(jb);
      jp.add(jb1);
      jp.add(jl);
     jf.add(jp,"South");
      ta.setWrapStyleWord(true);
        jf.add(jsp);
        jf.setSize(600,400);
        jf.setVisible(true);
        int W = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
        int H = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
        jf.setLocation((W-jf.getWidth())/2,(H-jf.getHeight())/2);
    }

    //事件响应方法
    public void actionPerformed(ActionEvent e)
    {
  //存储,用到输入流
      if(e.getSource()==jb||e.getSource()==_fm2)
      {
   try
   {
    if(filename==null)
    {
          filename = JOptionPane.showInputDialog("请输入文件名","java");
          FileOutputStream fout = new FileOutputStream(filename+".txt");
          byte bb[] = ta.getText().getBytes();
          fout.write(bb);
          fout.close();
          JOptionPane.showMessageDialog(null,"已保存");
         }
         else
         {
           FileOutputStream fout = new FileOutputStream(filename+".txt");
           byte bb[] = ta.getText().getBytes();
           fout.write(bb);
           fout.close();
           JOptionPane.showMessageDialog(null,"已保存");
         }
        }
        catch(IOException ioe)
        {
          System.err.println(e);
        }
       }//if
       //新建
      if(e.getSource()==_fm)
      {
        if(!(ta.getText().equals("")))
        {
        Object[] options = {"确定","取消"};
         int response = JOptionPane.showOptionDialog(null,"你是否保存","提  示",JOptionPane.YES_OPTION,
         JOptionPane.QUESTION_MESSAGE,null,options,options[0]);
         //确定
         if(response==0)
         {
     try
     {
           FileDialog d = new FileDialog(jf,"保存文件",FileDialog.SAVE);
         d.setVisible(true);
         filename = d.getDirectory()+d.getFile();
           FileOutputStream fout = new FileOutputStream(filename+".txt");
           byte bb[] = ta.getText().getBytes();
           fout.write(bb);
           fout.close();
           JOptionPane.showMessageDialog(null,"已保存");
           ta.setText("");
          }
          catch(IOException ioe)
          {
            System.err.println(e);
           }
         }//if
         if(response==1)
         {
     JOptionPane.showMessageDialog(null,"你选择了取消");
          ta.setText("");
         }//if
       }//if
       filename = "";
      }//if
      //打开
      if(e.getSource()==_fm1)
      {
       FileDialog d = new FileDialog(jf,"打开文件",FileDialog.LOAD);
       d.setVisible(true);
       File f = null;
       f = new File(d.getDirectory()+d.getFile());
       //读取文件到编辑区
        for(int i=0;i<=f.length();i++)
        {
    char [] ch = new char[i];
        try
        {
          FileReader fr = new FileReader(f);
          fr.read(ch);
          String str = new String(ch);
          ta.setText(str);

        }
        catch(FileNotFoundException fe)
        {

        }
        catch(IOException ie)
        {
         }
       }//for
     }//if
     //另存为
      if(e.getSource()==_fm4)
      {
        FileDialog d = new FileDialog(jf,"另存为",FileDialog.SAVE);
     d.setVisible(true);
        try
        {
       filename = d.getDirectory()+d.getFile();
        FileOutputStream fout = new FileOutputStream(filename+".txt");
         byte bb[] = ta.getText().getBytes();
         fout.write(bb);
         fout.close();
        }
        catch(IOException ioe)
        {
          System.err.println(e);
        }
      }//if
      //关闭
      if(e.getSource()==_fm3||e.getSource()==jb1)
       {System.exit(0);}
      //复制
      if(e.getSource()==_fe1)
      {
        copy = ta.getSelectedText();
     }
     //粘贴
      if(e.getSource()==_fe2)
     {
        ta.setText(copy);
      }
      //剪切
      if(e.getSource()==_fe3)
      {
        copy = ta.getSelectedText();
        ta.setText("");
      }
      //作者
      if(e.getSource()==_fe4)
      {
        JOptionPane.showMessageDialog(jf,"作者:林伟华 \n        ! 提醒   好好学习,天天向上 \n学习JAVA很快乐!");
      }
   }
    public void windowClosing(WindowEvent e)
    {
      System.exit(0);
    }
}

posted @ 2008-12-23 22:16 小琳 阅读(403) 评论(0) 编辑

2008年12月12日

继《手机》中的“做人要厚道!”等经典台词被大众广为流传后,冯小刚在另一部电影《天下无贼》(A World Without Thieves)中也制造出不少有趣的台词:

1、I have said a hundred times,we need team work,always seek thebest in the team.the purpose of the trip,is to train our team in realsituation and to test our new members.those deserving special praiseare the little leaf and four eyes.although new to trade,they tryhard,they have not only surpass themselves,but even the old guard here.

“说了多少回了,要团结,眼睛要看这别人的长处。这次出来,一是通过实战锻炼队伍,二是考察新人,在这里我特别要表扬的是小叶和四眼。两位虽然刚刚入道,做人啊,不但突破了自己, 也超越了在座的前辈。

———葛优扮演的“贼头”黎叔在教训几个手下。

点评:集体出行时,拿此话来调侃,别人没准儿会高看你一眼。

2、What is the most expensive commodity in this century? talent!

“21世纪什么最贵?人才!!!

———“贼头”黎叔高瞻远瞩地告诉副手要注意考察新人。

点评:用此话表扬你身边的人,他会乐晕。

3、An organization without discipline.

“有组织,无纪律。”

———“贼头”黎叔在感叹手下“四眼”不听他的话,擅自“打猎”。

点评:为喜欢批评下属的头头儿节省唾液的实用佳句。

4、First my gaze toward the moon, but the moon shines on the ditch.

“我本一心向明月,奈何明月照沟渠”

5、Who knows me understand my needs, i’m a mystery to he who know me not .

“真是知我者谓我心忧,不知我者谓我何求啊”

———这两句“贼头”黎叔在叹息无法把看中的王薄收入麾下。

点评:此话以后必将超级流行,只要是谁拒绝了你的好意,你都可以端出此话感慨一番。

6、I can’t stand you armed robber types, no technical skills what so ever.

“我最讨厌你们这些劫匪了,一点技术含量都没有。”

7、I can reliably inform you that, uncle lee is very angry. the consequences will be severe。

“我可以很负责地告诉你,黎叔很生气,后果很严重。”

8、I was reckless, i was reckless,never thought that girl would play me。.

“大意呀,大意呀,想不到被一丫头片子玩儿了。”

转载自网上,略有删改。这些台词的翻译好像并不是很准确,大家就姑且一看,付诸一笑吧。

posted @ 2008-12-12 11:09 小琳 阅读(120) 评论(0) 编辑