GUI IVOutlineEvent handling exampleModel-view-controllerJTableMVC in JTableMore TypicalTableModelDefaultTableModelAbstractTableModelWhy a separate class?Handling ChangeOther ModelsEditing and RenderingExampleJTreeTreeModelTreeNodeEventsHomework #3db packagecore packagecmd packageui packageui package continuedAssignmentCommand Class New I/O MethodsExamineAdviceGUI IVIS 3135.8.2003OutlineEvent handling exampleModel-view-controllerJTableHomework #3Event handling exampleModel-view-controllerControllermanipulate-able interface modalityViewobservable interface displayModelunderlying data structureJTableMVC in JTableMore TypicalTableModel// Mandatoryint getColumnCount() int getRowCount() Object getValueAt(int rowIndex, int columnIndex) // For displayString getColumnName(int columnIndex) // For editingboolean isCellEditable(int rowIndex, int columnIndex) void setValueAt(Object aValue, int rowIndex, int columnIndex)// For renderingClass getColumnClass(int columnIndex) // For event handlingvoid addTableModelListener(TableModelListener l) void removeTableModelListener(TableModelListener l)DefaultTableModelVector of VectorsTo createDefaultTableModel(Object[ ][ ] data, Object[ ] columnNames) DefaultTableModel(Vector data, Vector columnNames) You can use the default table model implicitlynew JTable(Object[ ][ ] data, Object[ ] columnNames) new JTable(Vector data, Vector columnNames)AbstractTableModelSupplies default methods for most of the methodsSpecializers need implement onlyint getColumnCount() int getRowCount() Object getValueAt(int rowIndex, int columnIndex)Why a separate class?Efficiency 1no need to convert table to a different formEfficiency 2only generate those items that the user wants to seeModularityIsolate the form of data display from the data itselfHandling ChangeThe JTable needs to know when the model has changedTableModelListenerIf you have your own setValueAt methodyou must call fireTableCellUpdated (row, col)the JTable is a listenerOther ModelsTableColumnModelSeparate from the table dataColumns have their own display characteristicsvisible / hiddenwidthorderingListSelectionModelSelection is a set of intervalsIssue of “what is selected” can be complexTreeSelectionModelEditing and RenderingReturn a class with getColumnClassSome built-inBoolean = check-boxImageIcon = centered label containing the imageOtherwiseRegister an editor and/or renderer for that classtable.setCellEditor (Class, CellEditor)table.setDefaultRenderer (Class, Renderer)ExampleFlightTableModelJTreeTreeModel// essentialObject getRoot() Object getChild(Object parent, int index) int getChildCount(Object parent) int getIndexOfChild(Object parent, Object child) boolean isLeaf(Object node) // editabilityvoid valueForPathChanged(TreePath path, Object newValue) // event handlingvoid addTreeModelListener(TreeModelListener l) void removeTreeModelListener(TreeModelListener l)TreeNode// move downEnumeration children() TreeNode getChildAt(int childIndex) int getIndex(TreeNode node) int getChildCount() // move upTreeNode getParent() // statusboolean getAllowsChildren() boolean isLeaf()EventsTree expand/collapseTreeExpansionListenerNode selectionTreeSelectionListenerNode/tree modificationTreeModelListenerHomework #3FFGUIModeDifferencespackage structuredynamic command loadingautomatic path detectiongraphical interfacein-memory databasemust use JDK 1.4db packageClass related to data storage and retrievalFrequentFlyerDBmain class for interacting with the stored dataalso MemberDB and FlightDBMemberholds individual datahas miles valueFlightholds flight recordsMultiMapa utility class for a Map with multiple values for one keyDBUtilitieshome of various utility functionscore packageCommandMapmaps names to commandsloads commands at start upCommandSimpleCommandExitCommandHelpCommandMDatabaseCommand“M” indicates “memory” databasecmd packageAdding/deleting commandsMAddMemberCommandMAddFlightCommandMDeleteFlightCommandReporting commandsMShowMembersCommandMShowFlightsCommandFinding CommandsMFindByNameCommandMFindByLevelCommandMFindFlightsByMemberCommandUnknownCommandui packageFFTextModeFFGUIModeFFFramemenusCommandListenerexternal listener class for commandsPromptDialogdefault dialog for getting parameters for commandsResultDialogdefault dialog for displaying resultsui package continuedFlightDisplayDialogJTableFlightTableModelEnterLevelDialogCombo box for benefit levelEnterIdDialogAssignmentInput dialog for “add member”use appropriate componentsOutput dialog with a table of membersto be used by “show members”, “find by name”, “find by level”must use a table modelHelp dialogBut the set of commands is not fixed!Command ClassNew I/O MethodsgetParametersdetects modecalls getParametersText or getParametersGUIdefault implementations providedsubclasses must override getParametersGUI to display their own dialogsdisplayResultsdetects modecalls displayResultsText or displayResultsGUIdefault / must overrideExamineFFFrameCommandListenerMShowFlightsCommandMDeleteFlightCommandEnterIdDialogAdviceStart early!Draw your dialogs before implementingUse existing classes as
View Full Document