felito 0 Newbie Poster

hello guys

is the following, I have four players on the king, and I need to check if they are bluffing, because in the first round have to assist to the suit, so, I want a method that is used by four players

the question is now, so I have four scripts of code like that, one for each players

// PLAYER2
		ActionListener two = new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (gr1.getCounter2() < 5) {
					gr1.setCounter2(gr1.getCounter2() + 1);
					for (int i = 0; i < arraybtn.length; i++) {
						if (arraybtn[i] == e.getSource()) {
							test3.setIcon(pp.hand.get(i).getImage());
							pn3.setText(Integer.toString(pp.hand.get(i).toInt()));
							pn7.setText(pp.hand.get(i).toString());
							pn70.setText(pp.hand.get(i).suit());
							gr1.validCard(pp.hand, pn70, pn50, i); //check
						}
					}
				} else {
					pn7.setText("No more cards");
				}
			}
		};

and another class, the following method. now my problem is that method only check the JTextField pn70 (second player) in relation to the JTextField pn50 (first player), and I don't want to have to replicate the method N times.

now how do I get the generic method? to be used for all players?

@Override
	public boolean validCard(List<Card> hand, JTextField pn70, JTextField pn50, int i) {
		if(pn70.getText().equals (pn50.getText())) { // problem here
			System.out.println("you assist");
			return true;
		} else {
			for (Card card : hand) {
				  if (card.suit().equals(pn50.getText())) {
						System.out.println("existe");  
				  }
				return false;
				}
		}
		return true;
	}

thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.