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(300, 200); 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); }}