问题描述
我目前正在使用MVC模式在Java中实现纸牌游戏,但是在视图方面遇到很多困难.实际上,我有很多模型类和很多视图(可观察模型的观察者),例如玩家",甲板",卡牌",游戏"等.
I'm currently implementing a card game into java using MVC pattern but I've got lots of difficulties with views. In fact, I've got many models classes and so many views (which are Observers of the Observable models) such as "Player" "Deck" "Card" "Game" etc...
为了拥有图形用户界面,我问我是否应该仅使用一个JFrame(但是在这种情况下,所有视图如何在同一个JFrame上起作用?)还是创建多个JFrame,例如每个视图都扩展了JFrame?这是我第一次使用MVC模式,但对我来说仍然很模糊:/
In order to have a graphical user interface I'm asking if I should use only one JFrame (but in this case how can all the views act on the same JFrame ?) or create multiple JFrame such as each view extends JFrame ? It's my first time using MVC pattern and it remains really fuzzy for me :/
推荐答案
单个框架就足够了.实际上,一个视图(Deck扩展了JPanel)可以包含多个其他视图(Cards扩展JPanel),提供了布局和委派卡片绘制和事件处理的功能.
Single frame is enough. In fact one view (Deck extends JPanel) could contains multiple another views (Cards extends JPanel) providing layout and delegating to cards painting and event processing.
这篇关于MVC和JFrames的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!