DOC PREVIEW
UNC-Chapel Hill COMP 401 - comp401sp13lecture22ModelViewController

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Model&/&View&COMP&401&Spring&2013&Lecture&22&4/9/2013&ColorChooser&Widget&Review&• lec21.v7&• Color&object&embedded&within&the&widget&– Fine&for&a&small&piece&of&immutable&informaJon&– Not&so&great&for&a&complex&abstracJon&• UI&may&not&always&be&needed&Model&–&View&PaQern&• Keep&object&represenJng&the&data&separate&from&widget&providing&the&UI&– Model:&Object&represenJng&abstracJon&within&your&applicaJon.&– View:&Object&(widget)&represenJng&UI&to&model.&COMP&401&::&Spring&2012& 3&Model& View&Inform&when&data&changes.&Inform&when&user&interacts.&ModelVView&Example&• Playlist&– This&is&the&model&object&– Manages&a&list&of&Song&objects&• PlaylistView&– This&is&the&view&object&– Provides&a&UI&for&interacJng&with&Playlist&lec22.v1&• Playlist&lec22.v2&• PlaylistView&– Encapsulates&a&reference&to&Playlist&object&– Builds&a&simple&view&of&the&playlist&lec22.v3&• AddSongWidget&– An&interface&for&adding&a&new&song&to&the&Playlist&lec22.v4&• ConnecJng&model&to&view&– Model&needs&to&inform&the&view&whenever&it&changes&so&that&the&view&can&rebuild&to&reflect&any&changes.&• My&approach&here&is&to&make&the&model&observable.&– And&to&register&PlaylistView&as&an&observer&• Notes:&– revalidate()&required&whenever&contents&of&a&Java&Swing&container&are&changed&lec22.v5&• NoJce&duplicaJon&of&code&in&constructor&when&list&is&first&built&and&when&rebuilt&when&responding&to&model&update.&– Refactor&into&a&helper&method.&• JScrollPane&– Wraps&another&Swing&component&that&may&change&size&and&provides&scrolling&view&as&needed.&lec22.v6&• Add&a&shuffle&buQon&lec22.v7&• Create&more&interesJng&song&lisJng&– SongLisJngWidget&• Includes&a&buQons&for&removing&the&song&from&the&playlist&and&moving&them&up&and&down&the&list.&• BorderFactory&– Swing&class&for&creaJng&borders&for&components&• Unicode&characters&– Lots&of&glyphs&available&– Changed&Song&to&use&star&glyph&for&raJng&• Added&method&to&playlist&for&moving&songs&Model&/&View&Model& View&Inform&when&data&changes.&Inform&when&user&interacts.&Playlist&/&PlaylistView&Playlist&PlaylistView&update()&shuffle()&AddSongWidget&addSong()&SongLisJngWidget&SongLisJngWidget&SongLisJngWidget&SongLisJngWidget&SongLisJngWidget&SongLisJngWidget&removeSong(),&moveSong()&Model&/&View&Summary&• Model&provides&access&to&an&abstracJon.&– Any&manipulaJon&/&modificaJon&done&via&public&methods&provided&by&model.&• View&builds&an&interface&for&rendering&current&state&of&the&model.&– InteracJons&with&interface&translated&to&appropriate&calls&on&model&methods.&ModelVView&Inadequacies&• Good&for&simple,&direct&UI&elements&– Model&driving&UI&is&just&one&object&– UI&reflects&model&state&directly&– User&interacJons&with&view&have&direct&mapping&to&updates&to&model.&• Complex&behavior&harder&to&express&– Dynamic&user&interfaces&– Complex&models&– Contextual&user&interacJons&COMP&401&::&Spring&2012& 15&Classic&MVC&COMP&401&::&Spring&2012& 16&hQp://www.oracle.com/technetwork/arJcles/javase/mvcV136693.html&Alternate&MVC&COMP&401&::&Spring&2012& 17&hQp://www.oracle.com/technetwork/arJcles/javase/mvcV136693.html&A7&• ChessGame,&ChessPiece&make&up&the&model&• ChessGameView&is&view&•


View Full Document

UNC-Chapel Hill COMP 401 - comp401sp13lecture22ModelViewController

Documents in this Course
Objects

Objects

36 pages

Recursion

Recursion

45 pages

Load more
Download comp401sp13lecture22ModelViewController
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view comp401sp13lecture22ModelViewController and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view comp401sp13lecture22ModelViewController 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?