开发者

How do I revert state of JToggleButton from another class?

I am trying to write simple vector graphics editor in Java and got stuck with GUI... I have 2 JPanels: First one is for the "canvas area", second one is for the buttons. Canvas area is a Singleton, so then button pressed, it calls method of the Singleton and it adds element to list of the Singleton and re-paints the area. But now, I want to change these buttons to JToggleButtons and don't know how to revert it's state after click on the canvas.

Which design pattern should I use (because I have bad feeling that I'm doing it wro开发者_如何学Cng)?


Have you ever heard of call backs? Once they are understood and implemented correctly, they can work quite nicely.

http://en.wikipedia.org/wiki/Callback_(computer_science)

I like this example too. http://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ310_019.htm


Make use of the Command and Memento patterns. Implement an Undo Command. Allow commands to store state in the form of a Memento. Restore the state from the Caretaker when you find fit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜