应一个朋友要求,定制一个java写字板程序(试用版)

package  com.guiawt;
 
import  java.awt.FileDialog;
import  java.awt.Font;
import  java.awt.Frame;
import  java.awt.Menu;
import  java.awt.MenuBar;
import  java.awt.MenuItem;
import  java.awt.TextArea;
import  java.awt.event.ActionEvent;
import  java.awt.event.ActionListener;
import  java.awt.event.WindowAdapter;
import  java.awt.event.WindowEvent;
import  java.io.FileInputStream;
import  java.io.FileNotFoundException;
import  java.io.IOException;
 
public   class  Guiawt  {
 
    
/**
     * 
@param args
     
*/

    
public static void main(String[] args) {
        
final Frame f=new Frame("Title");
        f.setSize(
700,500);
        f.setLocation(
300200);
        f.addWindowListener(
new WindowAdapter(){
                
public void windowClosing(WindowEvent e){
                    System.exit(
0);
                }

        }
);
         
        
final TextArea ta=new TextArea();
        ta.setFont(
new Font("宋体",Font.PLAIN,16));
        ta.setEditable(
true);
        f.add(ta);
        MenuBar mb
=new MenuBar();
        Menu m1
=new Menu("File");
        Menu m2
=new Menu("Edit");
        MenuItem mt1
=new MenuItem("New");
         
        MenuItem mt2
=new MenuItem("Open");
        mt2.addActionListener(
new ActionListener(){
            
public void actionPerformed(ActionEvent e) {
                FileDialog fd
=new FileDialog(f,"Open File",FileDialog.LOAD);
                fd.setLocation(
300,200);
                fd.setVisible(
true);
                String str
=fd.getDirectory()+fd.getFile();
                
if(str!=null){
                    ta.setText(
"");
                    
try {
                        FileInputStream fis
=new FileInputStream(str);
                        
byte[] buf=new byte[100*1024];
                        
try {
                            
int len=fis.read(buf);
                            ta.append(
new String(buf,0,len));
                            fis.close();
                        }
 catch (IOException e1) {
                            e1.printStackTrace();
                        }

                    }
 catch (FileNotFoundException e1) {
                        e1.printStackTrace();
                    }
 
                }

            }

        }
);
         
        MenuItem mt3
=new MenuItem("Save");
         
        MenuItem mt4
=new MenuItem("Quit");
        mt4.addActionListener(
new ActionListener(){
            
public void actionPerformed(ActionEvent e) {
                System.exit(
0);
            }

        }
);
         
        MenuItem mt5
=new MenuItem("Copy");
        MenuItem mt6
=new MenuItem("Paste");
         
        m1.add(mt1);
        m1.add(mt2);
        m1.add(mt3);
        m1.add(mt4);
        m2.add(mt5);
        m2.add(mt6);
         
        mb.add(m1);
        mb.add(m2);
         
        f.setMenuBar(mb);
         
         
        f.setVisible(
true);
    }

}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值