English 中文(简体)
• 如何在MVC Java实施我的法典?
原标题:How to implement my code in MVC Java?

我正在游戏中进行三场游戏。 我开始用一个班子拿走我的代码,因为我现在想把它推向我有错误的多国公司格式。 我开始撰写所有《博爱》类的法典,我现在想将其中一些法典从这一类移至SView级。 问题在于,我已经将JFrame列入“游戏”课堂,在我把我的法典提升到SView级时,它无法找到变化的框架。 因此,我被告知要把它变成一个小组,然后把它推向一个小组,但只是想起我的游戏。

问题回答

You have to organize things a little differently. Some things to consider:

  • Is GameView your main window? Make it so GameView extends JFrame.
  • Is SView a panel? Make it so SView extends Panel.

Another thing to think about: SView is some panel that you want to add to your GameView, but it s not the responsibility of SView to add itself. Instead, simply instantiate and assemble these components somewhere outside both of these classes, f.e.:

GameView gameView = new GameView();
gameView.add(new SView());

也可以有<条码>GameView,在《建筑商法典》中添加“条码”。

Anyway, the main point here is that a component should not concern itself with adding itself to its parent, just with creating its own content/children.

Good luck.

一些建议:

  • The main GUI would use a CardLayout so you can swap JPanels easily.
  • The main function of the select game menu will be to swap JPanels, so the game selected is visualized and then initialize the selected game.
  • Work on each game individually. Gear each individual game class towards produding a JPanel to hold the game. Give each game class a main method for testing that would create a JFrame, create a game class instance, place the instance s JPanel into the JFrame, initialize the game and display it.
  • Once the game is working on its own, try adding it to your larger GUI, the one that can show multiple games.
  • Consider having each game class implement a common interface for common functionality. For example you could give the interface an initialize() method that each game class would override.
  • Each game class would need to be MVC-based so that it has a model, a control class(es) to interact with the model and a view class that displays the state of the model on the JPanel as noted above.




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签