免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2127 | 回复: 2
打印 上一主题 下一主题

[GUI programming] How do two JPanels interact? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-25 19:29 |只看该作者 |倒序浏览
Hi, all

I've been looking if there is a standard/mostly-used way implementing GUI applications. e.g.,

under a JFrame, there are 2 MyPanel exntending JPanel, one placed on the leftside, the other on the rightside. they both have got a bunch of JButtons, JLabels, JList, etc. this is the view.

but for the control part, here comes the question: I'd would like PanelA to change background color if a Button on PanelB is pressed. where should I place this part of code that controls what happen. I've considered some possibilites, but not sure which one is the best.

1. implement it in main() like: if PanelA.Button.isPressed(), then PanelB.setBackground(Green)
pros: centrailized control
cons: could lead to long & messy code if there are many Panels needed to control

2. PanelA as Observer, PanelB Observable
pros: doable
cons: not very convenient

3. PanelA & PanelB both singleton, so they can reference to each other directly
pros: easy implementing
cons: less flexibility

if none of them is the way you do, how do you do it then?

any help will be appreciated.

thanks.

论坛徽章:
0
2 [报告]
发表于 2008-06-26 01:34 |只看该作者
你好,我想你需要的是一种简单的、灵活的且能够重用的方式去开发一个 GUI 应用。我不想给出你这个例子的代码了,因为没时间。但我推荐你看一篇文章 http://www.ibm.com/developerworks/cn/views/java/tutorials.jsp?cv_doc_id=110085 这是 IBM developerworks 上的一篇关于 Spring 开发 Swing GUI 的简单教程,你需要注册一个 IBM 帐号才能浏览。其中用到了 Spring 的依赖注入(dependency injection),你可能需要学习一下相关知识。看完此教程,我想你应该知道如何开发一个良好的客户端程序。对于该教程中例子,如果你不想使用 Spring 的话,可以自己写一个管理类来替代 xml 配置文件,关键是编程的思想。最后建议你去熟悉一下 Spring RCP 和 Eclipse RCP 两个框架,如果你真的要做 GUI 的话。Good lucks!

[ 本帖最后由 Jae_Cheung 于 2008-6-26 01:44 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2008-06-26 01:54 |只看该作者

回复 #2 Jae_Cheung 的帖子

tried to create a account for myself, did not succeed thoug.

it is interesting to see that your first post in this forum is to response to me. i've been honored.

thanks.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP