//Edit import java.awt.*; import java.io.*; public class Edit extends Frame{ Button btnSave = new Button("Save"); Button btnLoad = new Button("Load"); Button btnQuit = new Button("Quit"); TextArea txtEdit = new TextArea(); Panel pnlSouth = new Panel(); public Edit(){ super("Editor"); pnlSouth.add(btnSave); pnlSouth.add(btnLoad); pnlSouth.add(btnQuit); add("Center", txtEdit); add("South", pnlSouth); } // end constructor public static void main(String args[]){ Edit f = new Edit(); f.resize(300,200); f.show(); } // end main public boolean handleEvent(Event e){ if (e.target == btnSave){ saveFile(); return true; }else if (e.target == btnLoad){ loadFile(); return true; }else if (e.target==btnQuit){ System.exit(0); return true; } else if(e.id == Event.WINDOW_DESTROY){ System.exit(0); return true; } else { return false; } // end if } // end handleEvent private void saveFile(){ //handle saving stuff //get the file from the user FileDialog fd = new FileDialog(this, "Save to...", FileDialog.SAVE); fd.setFile("*.txt"); fd.show(); // open the output stream try { DataOutputStream os = new DataOutputStream( new FileOutputStream(fd.getFile())); //send out the data os.writeUTF(txtEdit.getText()); //clean up shop os.close(); } catch (IOException excep){ System.out.println (excep); } // end try } // end saveFile private void loadFile(){ //get the file from the user FileDialog fd = new FileDialog(this, "Load from...", FileDialog.LOAD); fd.setFile("*.txt"); fd.show(); try{ //do loading stuff DataInputStream is = new DataInputStream( new FileInputStream(fd.getFile())); //bring it in... txtEdit.setText(is.readUTF()); is.close(); } catch (IOException excep){ System.out.println (excep); } // end try } // end loadFile() } // end class def