CIS525 - Lecture#16 - October 30, 2000

CIS 525 10/30/00 many questions re: Java assignent... ...Dilbert today: "The Smart-Alek Intern"
menus: page 549, ColorMenu.java 1) create new menu bar 2) create menu with names 3) add strings or other menus 4) add menu to menu bar 5) show
Serialization: Java 1.1 page 553 save the state of Java objects or broadcast over network - make sure all objects referenced by windows are 'serializable', (use interface), all awt objects are serializable writing a window to disk: try{ fileOutputStream fileOut = new FileOutStream("_"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(SomeWindow); out.flush(); out.close(); } catch(IOException ioe) { System.out.println("Error saving window: " + ioe); } On page 554, reading window from disk: try { File saveFile = new File("SaveFilename:); FileInputStream fileIn = new FileInputStream(saveFile); ObjectInputStream in = new ObjectInputStream(fileIn); SomeWindow = (WindowType)in.readObject(); doSomethingWith(someWindow); gzipInputStream() for compressed files
Dialog - Page 559: - specialized frame modal or not modal, modal = all action freezes until some response is registered - default layout manager is BorderLayout creating and using: 1) modal or not 2) to use from applets, getFrame() See Page 561 Confirm.java
File dialog - Page 563: modal, (save or load files) no default layout manager => not a container object creating and using: 1) make file dialog fileDialog fileLoader = new FileDialog(frame, title, FileDialog.LOAD); FileDialog fileSaver = new FileDialog(frame, title, FileDialog.SAVE); 2) set default file or type fileLoader getFile("*.txt"); 3) pop-up fileDialog fileLoader.show(); 4) look up the file name String fileName = fileLoader.getFile(); See Page 565-568, DisplayFile.java
Windows - page 571: - pop up application no title Fixed size window - Page 569: 1) create window 2) add component() 3) resize window (stretch pack) 4) display window (stretch pack) Popup.java page 571
Next lecture: Layout Managers, Chapter 12 1) flow layout 2) border layout 3) grid layout 4) card layout 5) grid bag layout consider nesting each container object so each has a layout manager