multicardd.java

来自「一个非常不错的java纸牌游戏源代码」· Java 代码 · 共 81 行

JAVA
81
字号
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * For when player wants to play more than one card of the same suit
 * 
 * @author Sam Cavenagh
 * @version 21/11/02
 * 
 * Website: http://home.pacific.net.au/~cavenagh/SH/
 * Email: cavenaghweb@hotmail.com
 */
public class MultiCardD extends JDialog implements ActionListener {

	JLabel question = new JLabel("How many cards would you like to play ?");

	JButton buttons[] = new JButton[4];

	JPanel panel;

	int choice = 1;

	public MultiCardD(JFrame parent, int cardcount) {

		super(parent, "MultiCard Selection", true);
		setSize(280, 80);

		Point p = parent.getLocation();
		setLocation((int) p.getX() + 60, (int) p.getY() + 400);

		panel = new JPanel();
		GridBagLayout gridbag = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();
		panel.setLayout(gridbag);
		//c.anchor = GridBagConstraints.WEST;
		c.fill = GridBagConstraints.HORIZONTAL;
		getContentPane().add(panel);

		c.gridy = 1;
		c.gridwidth = cardcount;
		panel.add(question, c);

		c.weightx = 1;
		c.gridy = 2;
		c.gridwidth = 1;

		buttons[0] = new JButton("Play 1");
		buttons[1] = new JButton("Play 2");
		buttons[2] = new JButton("Play 3");
		buttons[3] = new JButton("Play 4");

		if (cardcount > 4)
			cardcount = 4;

		for (int n = 0; n < cardcount; n++) {
			panel.add(buttons[n], c);
			buttons[n].addActionListener(this);
		}

	}

	public void actionPerformed(ActionEvent e) {
		String pressed = e.getActionCommand();
		if (pressed.equals("Play 1"))
			choice = 1;
		if (pressed.equals("Play 2"))
			choice = 2;
		if (pressed.equals("Play 3"))
			choice = 3;
		if (pressed.equals("Play 4"))
			choice = 4;
		setVisible(false);
	}

	public int getChoice() {
		show();
		return choice;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?