Class Note for C SC 335 at UA
Popular in Course
Popular in Department
This 4 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Arizona taught by a professor in Fall. Since its upload, it has received 13 views.
Reviews for Class Note for C SC 335 at UA
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/06/15
C s 335 Sectinn L and Sanv Read th5 page and drseuss Java s Observer elass and rts Observable lnterface Begln the exerclse m patrs or 5010 ModeerlewrController MVC ls a elassre deslgn pattern olten used by applreauons thatneedthe abrlrtv to rnatntatn rnultrple mews ofthe sarne data The MVC pattern hlnges on a elean separauon of objects rnto one ofthree eategones 7 rnodels formamtammg data mews for dlsplaylng all or a poruon othe data and eontrollers for handllng events that affect the rnodel orvlews Beeause othls separatron rnultrple mews and eontrollers ean rnterfaee wrth the sarne rnodel Even new types ofvlews and eontrollers that never exlstedbefore ean rnterfaee wrth a rnodel wrthout forclng a ehange m the rnodel deslgn The MVC abstraetron ean be graphreallv represented as follows Mm u vnued tuttte cnnho el Comnnel ettnuues Cunnullev Made a Vlewtsl W Wquot lt 355133 may upaules Vluu when Eula mum Events tvpreallv eause a eontroller to ehange a rnodel ormew or both Whenever a eontroller changes a rnodel39s data or propertres all dependent mews are autornatreallv updated Slmllarly whenever a eontroller changes amew for example by reveallng areas that were premouslv hrdden the mew gets data from the underlylng rnodel to refresh ltself 0h serverObservahle The observer pattern usually plays apart m MVC Java promdes support wrth the Observer elass and Observable rnterfaee The deslgn allows one Observable to notlfy all regrstered observables that a ehange of state has oeeurred observable ltltlmar cegtgt etur ubsezvers Observer a my39 updatdohsemhle addohserverohserver statechanged o mp mms nuufyOhsen ers A lpunel aemurnrnmsem unpdautthe I SmlpleMudelmeThePast vlewOne mam rcuunlermt u ta Hntr nemo new rm cun39emCUun390 lnt PM mpmm Exercise Usmg the uml diagram and screenshuts helew m teams ufz setup the nude te have the Euntmlla39 lelusers ehekthe hutteh that sends a message tn the mudel which m tum heta es the ubservers uf the state change The mudel En send seeeecheheee and nut azyoeseevee mesege rum anywha39e when it thmks ubservers shuuld khewthe state has changed The mew updates xtselfby shuwmg an m1 m the meat culur uf39hemude that ehanges aeeemmgte its uwnmles these are gven m the nhangeCulurmmhud Java dass GBullunLIslener v Java dass 9 Eunlruller quote muaet39 Mme e WEN Aew e statauuen JEuttDn a men 9 mtqu use use a AEW o uavntoampanent 9 update 7 Java dass G Mudel a hv m Randum a Mide a getcuvventcmev a changecme r HEB harm am 0mm mu Chumquot om In Section Activity 2 and 3 NOV 1 SL public class Model extends Observer private Color currentColor private Random generator public Model generator new Random currentColor new Colorgeneratornextlnt256 generatornextlnt256 generatornextlnt256 public void changeColor int red currentColorgetRed 4 256 int green currentColorgetGreen 17 256 int blue currentColorgetRed 28 256 currentColor new Colorred green blue 1 Send the two messages the update message all observers l Add anything else you need public class Controller extends JFrame public static void mainString args Controller controller new Controller controllersetVisibletrue private Model model private View view private JButton startButton new JButtonquotChange Colorquot public Controller setSize200 220 setDefaultCloseOperationJFrameEXIT70N7CLOSE Container cp getContentPane cpaddstartButton BorderLayoutNORTH startButtonaddActionListenernew ButtonListener 2 Register the observer view to be notified of state changes when the observed object model changes its state private class ButtonListener implements ActionListener public void actionPerformedActionEvent argO modelbrightenColor 3 Implement class View 4 If time permits Implement class ViewTwo to show the toString version of the model s current color in a Jlabel on a JPanel 5 What would you have to do for this second view to be swapped at runtime
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'