d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Why Doesnt This Work > The Method Call Changes Nothing
Add Reply New Topic New Poll
Member
Posts: 4,478
Joined: Feb 10 2010
Gold: 1,806.00
Jul 29 2012 11:38am
There must be some basic concept about classes that I dont understand.

PokerJFrame.java i have:

Code
   private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                        
     
       t.newhand();
   }                                        

 


In the hand class i have an array of player objects called players:

Code

public void newhand()
           {
    players[0].setstack(10009);//DOESNT WORK (still showes original value)
    blinds[0]=1;//shows 0
    blinds[1]=2;//shows 0
    setutg(blinds); // works
    postblinds(); //DOESNT WORK
    shuffle();//works
    activeplayer = utg;//works
}
  public void postblinds()
          {
      for(int n=0; n<10; n++){
          players[n].stackout(blinds[n]);//
      potin(n);
      }}
public void potin(double a)
       {
   pot = pot+a;
}


in the player class i have:

Code

public void setstack (double a){
   stack = a;
}
public void stackout (double a){
   stack = stack - a;
}



Hoping for a helping hand :)
Member
Posts: 4,478
Joined: Feb 10 2010
Gold: 1,806.00
Jul 29 2012 12:10pm
Sorry the problem was in the JFrame not in the above :)
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jul 29 2012 03:10pm
add logging and debug in the future.
Member
Posts: 4,478
Joined: Feb 10 2010
Gold: 1,806.00
Jul 30 2012 08:14am
thank you for the advise

I have a bonus quistion.

Which of the two following ways are the best (fastest execute/best programming practice)

JFrame needs to display the playernames in the hand.

1:
Quote
JFrame call (t.hand).
t.getname(1)

hand call
public String getname (int a)
        {
    return player[a].getname();
}

player method
public String getname ()
        {
  return name;
}


or

2:
Quote
JFrame call (t.hand).
Double.toString(t.getplayer(1).getstack())

hand method
public spiller getplayer (int a)
        {
  return player[a];
}
player method
public String getname ()
        {
  return name;
}


Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jul 30 2012 11:22am
Code
Double.toString(t.getplayer(1).getstack())

players are named after numbers?

use three layers. your UI should call a controller and ask for the name, then your controller (which tracks app state) should look into the player array and ask the player for its name
Member
Posts: 4,478
Joined: Feb 10 2010
Gold: 1,806.00
Aug 23 2012 03:41pm
Quote (carteblanche @ Jul 30 2012 06:22pm)
Code
Double.toString(t.getplayer(1).getstack())

players are named after numbers?

use three layers. your UI should call a controller and ask for the name, then your controller (which tracks app state) should look into the player array and ask the player for its name



Yes the players know which seat they are sitting at as does the hand.

Need some advise about the controller which u mention. Sounds like a good idea. But how does the controller keep track of the state of the JFrame.

At this point my hand class keeps track of the hand, poker rules, players, stacks etc.
The JFrame gives actions via "fold" button, "new hand" button etc.

But I need a way to let the JFrame know certain things. for example: When the players are all in. the hand class need to tell the JFrame to turn one card at a time and pause for a sec.
Alternatively this could be done by a controller. but it still needs to tell the JFrame to update the cards icons.

Dont know if I have made it clear what my problem is. But any constructive advise is valued.

This post was edited by tigeranden on Aug 23 2012 03:42pm
Member
Posts: 4,605
Joined: Sep 15 2011
Gold: 9,464.00
Aug 23 2012 03:47pm
most ui frames need to have a reloadUi function or similar, which is what you call when the backend representation has changed and you want the UI to update.

the reloadUi function ought to more or less be the same as the function you call at the very beginning when you load the UI for the first time. of course, you'll only want to reload the pieces that can actually change and not the ones that are static (i.e. menu bars etc)

i think in java, that function is even built into the frame's class - you just need to properly implement or override it.

This post was edited by irimi on Aug 23 2012 03:48pm
Member
Posts: 4,478
Joined: Feb 10 2010
Gold: 1,806.00
Aug 23 2012 04:17pm
Ty Irimi. Ill be looking at my code again tomorrow.

I have a method called drawboard() which takes the state of the board from the hand class and redraws board. But I can't figure out how to call it from the hand class.

Like the idea that the hand class just keeps track of the logical/mathematical side of the game, while other classes takes care of the graphics etc.
Member
Posts: 4,605
Joined: Sep 15 2011
Gold: 9,464.00
Aug 23 2012 04:39pm
your backend code should NEVER call any UI code.

your UI code should be able to keep track of the internal state and refresh whenever is necessary.

a controller doesn't need to keep track of "the state of the JFrame". UI code should be stateless - all it should ever do is reflect the state of the backend.

This post was edited by irimi on Aug 23 2012 04:44pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll