How to advance with the development of a real GUI using Java Swing and MVC

I am creating a Blackjack Card emulator. I am SCJP familiar with Core Java concepts. I have a very basic understanding of Java swings and awt. Already finished writing the main game logic, CLI logic. My design includes several classes, Dealer, player, table, card, casino and some others. Enumerations for cards and suites.

I read about MVC as a theoretical concept familiar with the name "design patterns" (without understanding how they are implemented). Everywhere I am invited to learn when writing real code. So I started with this ...

I'm stuck now, how do I need to write code for my project? Writing GUI code and organizing it within existing code.

+3
source share
2 answers

, MVC ( , - ). , ​​ , ( , , , ). , . , , . , , , . .

: ( , , ).

+2

, .

, "" (.. ). . :

package casino.blackjack.model;
class DealtCards
{..}

, , , JPanel - Swing. , , :

package casino.blackjack.view;
class DealtCardsView
{..}

DealtCards , , , - . , "". , . .

package casino.blackjack.view;
class DealtCardsView
{
  JButton hitMeButton = new JButton("HIT");
  DealtCards cards;

  public DealtCardsView(DealCards myCards)
  {
     cards = myCards;
     renderCards();
  }

  private void renderCards(){.. do something..}

}

, , DealtCards . , . , . ActionListener. ( "" ), . , . , "". , , , .

package casino.blackjack.controller;
class DealtCardsController implements ActionListener
{
  DealtCards cards;
  DealtCardsView cardView;
  public DealtCardsController(DealtCards myHand, DealtCardsView myView)
  {
    cards = myHand;
    cardView = myView;
    cardView.hitMeButton.addActionListener(this);
  }

  public void actionPerformed(ActionEvent e) 
  {
    cards.changed();
  }
}

, . ( ) , . . , , , , .
, (, ), .
, , !

EDIT: MVC : java/gwt UI- -

+1

Source: https://habr.com/ru/post/1734116/


All Articles