FileDocCategorySizeDatePackage
Editor.javaAPI DocExample1557Sun Feb 23 22:56:22 GMT 1997None

Editor

public class Editor extends Frame implements ActionListener

Fields Summary
TextArea
textArea
Constructors Summary
Editor()


	 
		super("Editor");
		setLayout( new BorderLayout() );
		add("Center", textArea);
		Menu menu = new Menu ("File");
		menu.add ( makeMenuItem ("Load") );
		menu.add ( makeMenuItem ("Save") );
		menu.add ( makeMenuItem ("Quit") );
		MenuBar menuBar = new MenuBar();
		menuBar.add ( menu );
		setMenuBar( menuBar );
		pack();
	
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

		String command = e.getActionCommand();
		if ( command.equals("Quit") )
			dispose();
		else if ( command.equals("Load") )
			loadFile();
		else if ( command.equals("Save") )
			saveFile();
	
private voidloadFile()

		FileDialog fd = new FileDialog( this, "Load File", FileDialog.LOAD );
		fd.show();
		String file = fd.getFile();
		if ( file == null ) // Cancel
			return;
		try {
			FileInputStream fis = new FileInputStream ( fd.getFile() );
			byte [] data = new byte [ fis.available() ];
			fis.read( data );
			textArea.setText( new String( data ) );
		} catch ( IOException e ) { 
			textArea.setText( "Could not load file..." );
		}
	
public static voidmain(java.lang.String[] s)

		new Editor().show();
 	
private java.awt.MenuItemmakeMenuItem(java.lang.String name)

        MenuItem m = new MenuItem( name );
        m.addActionListener( this );
        return m;
    
private voidsaveFile()

		FileDialog fd = new FileDialog( this, "Save File", FileDialog.SAVE );
		fd.show();
		// Save file data...