I had a task at university of making an application using observer pattern to pass the subject (basics of programming). I wanted to show more knowledge, that it is included in syllabus and it backfired on me. I made an application in Swing + sql, heavily dependable on ActionListeners, which I thought, are a significant example of observer pattern. Unfortunately, my project was rejected because I did not write my own implementation of Observer pattern.
My question is, is that even possible with Swing to replace default action listener? I cannot even check a state of a button outside of it. I am really confused at the moment, even though I know the principles of a pattern and looking for help from your side.
Three common ways to implement the observer pattern in Swing are described here . The simplest to emulate would be Observer
, a single-method interface, and Observable
, a class that holds (in effect) a List<Observer>
. Invoking notifyObservers()
traverses the List
, calling the update()
method of each Observer
in the list.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.