MVC, Swing and exception in Java -
i'm developing game in java , i'm using mvc design pattern , swing gui. model, view , controller communicate between them observer/observable design pattern. in controller , in view must throw exception when player wants illegal action in game. example, if player wants buy in game has 0 coins, in view throw exception. there way show jdialog when exception throw show player can't action? can view catch exception of controller , of view?
maybe misunderstood question don't why throw exception in view. doesn't make sense me.
// model ///////////////////
class player{ int coin count = 0 setcoincount(int number){ // } getcoincount() { // } }
// controller ///////////////////
class cont{ model m; view v; cont(model m, view v){ // code.. } int checkbalance(){ return m.getbalance(); // balance model // sends view } }
// view ///////////////////
class view{ cont c; // when player click buy button ..... butonclick event handle.. (){ c.checkbalance(); // if balance 0 throw exception }
}
// main method ///////////////////
class mian{ psvm(string args[]){ // model , view doesn't know each other model m = new model() view v = new view() controller c = new controller (m , v ) v.setvisible true } }
Comments
Post a Comment