用Java实现一个简易的炸金花小游戏

news2024/9/20 0:49:10

最近闲暇时间写了个用Java实现的简易版的炸金花小游戏,还是很有趣的,下面具体来介绍下具体实现。
下面这个是初始化页面。
在这里插入图片描述
一、设计思路
1、首先要了解炸金花的游戏规则,针对整个游戏过程来考虑。从游戏开始后的抽牌选出庄家,再到洗牌及发牌阶段,接着投注或比牌,最终决出胜者。
2、在这整个过程中需要涉及洗牌算法,及比牌时的规则编写,电脑端投注或比牌等一系列操作。
3、在整个过程中需要考虑到各种情况,比如弃牌后不能再参与,首轮不能直接比牌等等。

游戏实际运行主界面如下:
在这里插入图片描述
二、代码实现:
1.初始化过程中的选出庄家,代码如下:

public void initGame() {
		Random rand=new Random();
		List<Integer> reduce=new ArrayList<>();
		if(this.t!=null) {
			this.t.isPublish = true;
		}
		for(int i=0;i<playerList.length;i++) {
			int j=0;
			if(reduce.isEmpty()) {
				j=rand.nextInt(card.length);
				reduce.add(j);
			}else {
				j=rand.nextInt(card.length);
				while(reduce.contains(j)) {
					j=rand.nextInt(card.length);
				}
				reduce.add(j);
			}	
			switch (i) {
			case 0:
				CommonUtil.move(card[j], card[j].getLocation(), new Point(100, 200));
				card[j].turnFront();
				break;
			case 1:
				CommonUtil.move(card[j], card[j].getLocation(), new Point(390, 515));
				card[j].turnFront();
				break;
			case 2:
				CommonUtil.move(card[j], card[j].getLocation(), new Point(800, 200));
				card[j].turnFront();
				break;
			case 3:		
				CommonUtil.move(card[j], card[j].getLocation(), new Point(390, 60));
				card[j].turnFront();
				break;
			}
			playerList[i].add(card[j]);
			container.setComponentZOrder(card[j], 0);
		}
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			return;
		}
		if(this.t!=null) {
			this.t.isPublish = false;
		}
		confirmBanker(playerList);
		for(Integer index : reduce) {		
			card[index].turnRear();
			card[index].setLocation(400, 250);
		}
		
		for(int i=0;i<inigoldLabel.length;i++) {
			inigoldLabel[i].setVisible(true);
			container.setComponentZOrder(inigoldLabel[i],0);
			playerGold[i]-=initGold;
			playergoldLabel[i].setText(playerGold[i]+"");
		}
		//设置开、放位置
		openCardIcon[0].setLocation(95, 185);
		quitCardIcon[0].setLocation(135, 185);
		//openCardIcon[1].setLocation(125, 210);
		quitCardIcon[1].setLocation(545, 520);
		openCardIcon[2].setLocation(795, 185);
		quitCardIcon[2].setLocation(835, 185);
		openCardIcon[3].setLocation(535, 80);
		quitCardIcon[3].setLocation(575, 80);
		
	}

2.选出庄家后开始发牌,代码如下:

public void publishCard() {
		for(int i=0;i<4;i++) {
			isFirst[i]=false;
			currPlayerGold[i]=10;
		}
		int t=0;
		int count=0;
		if(this.t!=null) {
			this.t.isPublish = true;
		}
		for(int i=currIndex;i<card.length;i++) {
			if(count==12) {
				currIndex=i-1;
				break;
			}
			switch (t++%4) {
			case 0:
				CommonUtil.move(card[i], card[i].getLocation(), new Point(90, 250+i*4));
				playerList[0].add(card[i]);
				break;
			case 1:
				CommonUtil.move(card[i], card[i].getLocation(), new Point(420+i*6, 510));
				playerList[1].add(card[i]);
				break;
			case 2:
				CommonUtil.move(card[i], card[i].getLocation(), new Point(810, 250+i*4));
				playerList[2].add(card[i]);
				break;
			case 3:
				CommonUtil.move(card[i], card[i].getLocation(), new Point(420+i*6, 50));
				playerList[3].add(card[i]);
				break;
			}
			container.setComponentZOrder(card[i], 0);
			count++;
		}
		if(this.t!=null) {
			this.t.isPublish = false;
		}
		for(int i=0;i<4;i++) {
			CommonUtil.cardSort(playerList[i]);
			CommonUtil.rePosition(playerList[i], i,this);
		}		
		if(bankerFlag==1) {
			container.setComponentZOrder(laid,0);
			laid.setVisible(true);
		}
		if(bankerFlag==1) {
			time[1].setVisible(true);			
		}
	}

3.在比牌时需要判断双方之间牌面大小,代码实现:

public static int checkCards(List<Card> clist,List<Card> chooselist) {
		CardType cType=judgeCard(clist);
		CardType chooseType=judgeCard(chooselist);
		if(cType==CardType.c3 && getValue(clist.get(0))==14) {
			return 1;
		}
		if(chooseType==CardType.c3 && getValue(chooselist.get(0))==14) {
			return 0;
		}
		if(cType==CardType.c3 && chooseType!=CardType.c3) {
			return 1;
		}
		if(cType!=CardType.c3 && chooseType==CardType.c3) {
			return 0;
		}
		if(cType==chooseType) {
			if(cType==CardType.c3 && getValue(clist.get(0))>getValue(chooselist.get(0))) {
				return 1;
			}else if(cType==CardType.c2) {
				List<Card> c1=getOrder(clist);
				List<Card> c2=getOrder(chooselist);
				if(getValue(c1.get(0))>getValue(c2.get(0))) {
					return 1;
				}
				if(getValue(c1.get(0))==getValue(c2.get(0))) {
					//比较大小、花色
					if(getValue(c1.get(1))==getValue(c2.get(1))) {
						if(getColor(c1.get(1))<getColor(c2.get(1))) {
							return 1;
						}
					}else {
						if(getValue(c1.get(1))>getValue(c2.get(1))) {
							return 1;
						}
					}
				}else {
					if(getValue(c1.get(0))>getValue(c2.get(0))) {
						return 1;
					}
				}
			}else if(cType==CardType.c30123) {
				if(getValue(clist.get(0))>getValue(chooselist.get(0))) {
					return 1;
				}else {
					if(getValue(clist.get(0))==getValue(chooselist.get(0))) {//相同
						if(getColor(clist.get(0))<getColor(chooselist.get(0))) {
							return 1;
						}
					}
				}
			}else if(cType==CardType.c30 || cType==CardType.c1) {
				if(isSameCard(clist, chooselist)) {
					if(getColor(clist.get(0))<getColor(chooselist.get(0))) {
						return 1;				
					}
				}else {
					return compareCard(clist, chooselist);
				}
			}else if(cType==CardType.c123) {
				if(getValue(clist.get(0))>getValue(chooselist.get(0))) {
					return 1;
				}
			}			
		}else {
			if(cType==CardType.c30123) {
				return 1;
			}
			if(cType==CardType.c30 && chooseType!=CardType.c30123) {
				return 1;
			}
			if(cType==CardType.c123 && chooseType!=CardType.c30123 && chooseType!=CardType.c30) {
				return 1;
			}
			if(cType==CardType.c2 && chooseType!=CardType.c30123 && chooseType!=CardType.c30 && chooseType!=CardType.c123) {
				return 1;
			}
		}
		return 0;
	}

接着编写Swing主界面:

public class GameMain extends JFrame implements ActionListener,MouseListener{
	private static final long serialVersionUID = 1L;
	
	public Container container=null;
	
	int initGold=10;
	int[] playerGold=new int[4];
	int[] currPlayerGold=new int[4];
	//每轮投入金币数
	int[] currRoundPlayerGold = new int[4];
	JMenuItem restart,exit,about;
	JPanel goldPanel;
	//比牌panel
	JPanel comparePanel;

	JLabel[] goldLabel=new JLabel[4];
	JLabel[] compareLabel=new JLabel[4];
	
	JLabel[] inigoldLabel=new JLabel[4];
	
	JLabel[] playergoldLabel=new JLabel[4];
	
	public static final int START=0;
	public static final int RUNNING=1;
	public static final int OVER=2;
	public static int state=START;
	JButton laid,addLaid,followLaid,compareCard,openCard,discard;
	
	int bankerFlag;
	boolean nextPlayer;
	
	boolean laidIsClick=false;
	boolean addlaidIsClick=false;
	boolean compareCardIsClick=false;
	int currIndex=0;
	
	JLabel banker;
	JLabel[] openCardIcon=new JLabel[4];
	JLabel[] quitCardIcon=new JLabel[4];
	int[] openFlag=new int[4];
	int[] quitFlag=new int[4];
	List<Card> playerList[]=new ArrayList[4];
	
	Card[] card=new Card[52];
	
	JTextField[] time=new JTextField[4];
	JLabel jl=null;
	JMenuBar jMenuBar=null;
	Timer t;
	Thread thread;
	JLabel[] player=new JLabel[4];
	boolean[] isFirst=new boolean[4];
	int turn;
	int roundNum=1;
	
	public GameMain() throws InterruptedException {
		init();
		setMenu();
		this.setVisible(true);
		initCard();
		state = RUNNING;
		this.t=new Timer(this, 10,true);
		SwingUtilities.invokeLater(new Runnable() {			
			@Override
			public void run() {
				thread=new Thread(t);
				thread.start();			
			}
		});
	}
	public void initCard() {
		int count=0;
		for(int i=1;i<=4;i++) {
			for(int j=1;j<=13;j++) {
				card[count]=new Card(i+"-"+j, false);
				card[count].setLocation(350, 200);
				card[count].setVisible(false);
				container.add(card[count]);
				count++;
			}
		}
		Random rand=new Random();
		for(int i=0;i<card.length;i++) {
			int j=rand.nextInt(card.length-i);
			Card k=card[i];
			card[i]=card[j];
			card[j]=k;
		}
	}
	public void init() {
		container=this.getContentPane();
		this.setTitle("炸金花");
		this.setSize(900, 506);
		this.setLocationRelativeTo(getOwner());
		this.setResizable(false);
		container.setLayout(null);
		container.setBackground(new Color(80, 90, 255));
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jl=new JLabel(new ImageIcon("images/金花.png"));
		jl.setSize(900, 506);
		jl.setVisible(true);
		//jl.addMouseListener(this);
		container.add(jl);
	}
	public void setMenu() {
		jMenuBar=new JMenuBar();
		JMenu game=new JMenu("游戏");
		JMenu help=new JMenu("帮助");
		restart=new JMenuItem("重新开始");
		exit=new JMenuItem("退出");
		about=new JMenuItem("关于");
		exit.addActionListener(this);
		about.addActionListener(this);
		restart.addActionListener(this);
		game.add(restart);
		game.add(exit);
		help.add(about);
		jMenuBar.add(game);
		jMenuBar.add(help);
		jMenuBar.setVisible(false);
		this.setJMenuBar(jMenuBar);
		
		laid=new JButton("下注");
		addLaid=new JButton("加注");
		followLaid=new JButton("跟注");
		compareCard=new JButton("比牌");
		openCard=new JButton("看牌");
		discard=new JButton("弃牌");
		
		laid.setBounds(350, 455, 60, 20);
		laid.addActionListener(this);
		laid.setFocusPainted(false);
		laid.setVisible(false);
		container.add(laid);
		
		addLaid.setBounds(420, 455, 60, 20);
		addLaid.addActionListener(this);
		addLaid.setFocusPainted(false);
		addLaid.setVisible(false);	
		container.add(addLaid);
		
		followLaid.setBounds(490, 455, 60, 20);
		followLaid.addActionListener(this);
		followLaid.setFocusPainted(false);
		followLaid.setVisible(false);	
		container.add(followLaid);
		
		compareCard.setBounds(560, 455, 60, 20);
		compareCard.addActionListener(this);
		compareCard.setFocusPainted(false);
		compareCard.setVisible(false);	
		container.add(compareCard);
		
		openCard.setBounds(630, 455, 60, 20);
		openCard.addActionListener(this);
		openCard.setFocusPainted(false);
		openCard.setVisible(false);	
		container.add(openCard);
		
		discard.setBounds(700, 455, 60, 20);
		discard.addActionListener(this);
		discard.setFocusPainted(false);
		discard.setVisible(false);
		container.add(discard);

		goldPanel=new JPanel();
		goldPanel.setVisible(false);
		goldPanel.setBounds(300, 415, 240, 50);
		goldPanel.setOpaque(false);
		container.add(goldPanel);
		comparePanel = new JPanel();
		comparePanel.setVisible(false);
		comparePanel.setBounds(300, 415, 240, 50);
		comparePanel.setOpaque(false);
		container.add(comparePanel);
		for(int i=0;i<4;i++) {
			time[i]=new JTextField("倒计时:");
			time[i].setVisible(false);
			
			container.add(time[i]);
			player[i]=new JLabel(new ImageIcon("images/玩家"+i+".png"));
			player[i].setVisible(false);
			container.add(player[i]);
			openCardIcon[i]=new JLabel(new ImageIcon("images/开.png"));
			openCardIcon[i].setSize(40, 40);
			openCardIcon[i].setVisible(false);
			container.add(openCardIcon[i]);
			quitCardIcon[i]=new JLabel(new ImageIcon("images/放弃.png"));
			quitCardIcon[i].setSize(40, 40);
			quitCardIcon[i].setVisible(false);
			container.add(quitCardIcon[i]);
			ImageIcon originalGoldIcon = new ImageIcon("images/gold.png");
			Image goldImage = originalGoldIcon.getImage();
			ImageIcon resizedGoldIcon = new ImageIcon(goldImage.getScaledInstance(25, 25, Image.SCALE_SMOOTH));
			goldLabel[i]=new JLabel((i+1)+"X", resizedGoldIcon, SwingConstants.CENTER);
			goldLabel[i].setBounds(i*65, 5, 45, 25);

			goldPanel.add(goldLabel[i]);
			goldLabel[i].addMouseListener(this);
			if (i!=1) {
				compareLabel[i]=new JLabel("玩家"+i);
				compareLabel[i].setForeground(Color.CYAN);
				compareLabel[i].setFont(new Font("黑体",Font.BOLD,13));
				if (i>0) {
					compareLabel[i].setBounds((i-1)*65, 5, 45, 25);
				}else {
					compareLabel[i].setBounds(i*65, 5, 45, 25);
				}
				compareLabel[i].setVisible(false);
				comparePanel.add(compareLabel[i]);
			}
			ImageIcon originalInitIcon = new ImageIcon("images/gold.png");
			Image initImage = originalInitIcon.getImage();
			ImageIcon resizedIcon = new ImageIcon(initImage.getScaledInstance(30, 30, Image.SCALE_SMOOTH));
			inigoldLabel[i]=new JLabel(initGold+"", resizedIcon, SwingConstants.CENTER);
			inigoldLabel[i].setFont(new Font("黑体",Font.BOLD,14));
			inigoldLabel[i].setForeground(Color.yellow);
			inigoldLabel[i].setVisible(false);
			container.add(inigoldLabel[i]);
		}
		inigoldLabel[0].setBounds(220, 280, 60, 40);
		inigoldLabel[1].setBounds(390, 350, 60, 40);
		inigoldLabel[2].setBounds(620, 280, 60, 40);
		inigoldLabel[3].setBounds(390, 205, 60, 40);
		
		time[0].setBounds(175, 235, 120, 20);
		time[1].setBounds(360, 395, 120, 20);
		time[2].setBounds(610, 230, 120, 20);
		time[3].setBounds(400, 165, 120, 20);
		
	}

	public void startGame() {
		container.remove(jl);
		this.setSize(1050, 720);
		jl = new JLabel(new ImageIcon("images/back.jpg"));
		jl.setSize(1050, 720);
		jl.setVisible(true);
		container.add(jl, 0);
		this.setLocationRelativeTo(getOwner());
		jMenuBar.setVisible(true);

		for (int i = 0; i < card.length; i++) {
			card[i].setVisible(true);
		}
		player[0].setBounds(30, 250, 50, 50);
		player[1].setBounds(330, 535, 50, 50);
		player[2].setBounds(740, 250, 50, 50);
		player[3].setBounds(330, 90, 50, 50);
		for (int i = 0; i < 4; i++) {
			playerList[i] = new ArrayList<>();
			container.setComponentZOrder(player[i], 0);
			player[i].setVisible(true);
			playerGold[i] = 1000;
			ImageIcon originalIcon = new ImageIcon("images/gold.png");
			Image image = originalIcon.getImage();
			ImageIcon resizedIcon = new ImageIcon(image.getScaledInstance(20, 20, Image.SCALE_SMOOTH));
			playergoldLabel[i] = new JLabel(playerGold[i] + "", resizedIcon, SwingConstants.CENTER);
			playergoldLabel[i].setVisible(true);
			playergoldLabel[i].setFont(new Font("黑体", Font.BOLD, 13));
			playergoldLabel[i].setForeground(Color.yellow);
			container.add(playergoldLabel[i]);
			container.setComponentZOrder(playergoldLabel[i], 0);
		}
		playergoldLabel[0].setBounds(20, 225, 60, 20);
		playergoldLabel[1].setBounds(320, 510, 60, 20);
		playergoldLabel[2].setBounds(730, 225, 60, 20);
		playergoldLabel[3].setBounds(320, 65, 60, 20);

		ImageIcon originalBankerIcon = new ImageIcon("images/庄主.png");
		Image originalBankerImage = originalBankerIcon.getImage();
		Image newBankerImage = originalBankerImage.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
		ImageIcon resizeBankerIcon = new ImageIcon(newBankerImage);
		banker = new JLabel(resizeBankerIcon);
		banker.setSize(45, 40);
		banker.setVisible(false);
		container.add(banker);
	}
	public void initGame() {
		Random rand=new Random();
		List<Integer> reduce=new ArrayList<>();
		if(this.t!=null) {
			this.t.isPublish = true;
		}
		for(int i=0;i<playerList.length;i++) {
			int j=0;
			if(reduce.isEmpty()) {
				j=rand.nextInt(card.length);
				reduce.add(j);
			}else {
				j=rand.nextInt(card.length);
				while(reduce.contains(j)) {
					j=rand.nextInt(card.length);
				}
				reduce.add(j);
			}	
			switch (i) {
			case 0:
				CommonUtil.move(card[j], card[j].getLocation(), new Point(100, 200));
				card[j].turnFront();
				break;
			case 1:
				CommonUtil.move(card[j], card[j].getLocation(), new Point(390, 515));
				card[j].turnFront();
				break;
			case 2:
				CommonUtil.move(card[j], card[j].getLocation(), new Point(800, 200));
				card[j].turnFront();
				break;
			case 3:		
				CommonUtil.move(card[j], card[j].getLocation(), new Point(390, 60));
				card[j].turnFront();
				break;
			}
			playerList[i].add(card[j]);
			container.setComponentZOrder(card[j], 0);
		}
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			return;
		}
		if(this.t!=null) {
			this.t.isPublish = false;
		}
		confirmBanker(playerList);
		for(Integer index : reduce) {		
			card[index].turnRear();
			card[index].setLocation(400, 250);
		}
		
		for(int i=0;i<inigoldLabel.length;i++) {
			inigoldLabel[i].setVisible(true);
			container.setComponentZOrder(inigoldLabel[i],0);
			playerGold[i]-=initGold;
			playergoldLabel[i].setText(playerGold[i]+"");
		}
		//设置开、放位置
		openCardIcon[0].setLocation(95, 185);
		quitCardIcon[0].setLocation(135, 185);
		//openCardIcon[1].setLocation(125, 210);
		quitCardIcon[1].setLocation(545, 520);
		openCardIcon[2].setLocation(795, 185);
		quitCardIcon[2].setLocation(835, 185);
		openCardIcon[3].setLocation(535, 80);
		quitCardIcon[3].setLocation(575, 80);
		
	}
	public void confirmBanker(List<Card> playerList[]) {
		int role= CommonUtil.compareCardSize(playerList);
		bankerFlag=role;
		
		switch (bankerFlag) {
		case 0:
			banker.setLocation(20, 185);
			break;
		case 1:
			banker.setLocation(320, 470);
			break;
		case 2:
			banker.setLocation(730, 185);
			break;
		case 3:
			banker.setLocation(320, 25);
			break;
		}
		banker.setVisible(true);
		container.setComponentZOrder(banker,0);
		for(int i=0;i<4;i++) {
			playerList[i].clear();
		}
	}
	public void publishCard() {
		for(int i=0;i<4;i++) {
			isFirst[i]=false;
			currPlayerGold[i]=10;
		}
		int t=0;
		int count=0;
		if(this.t!=null) {
			this.t.isPublish = true;
		}
		for(int i=currIndex;i<card.length;i++) {
			if(count==12) {
				currIndex=i-1;
				break;
			}
			switch (t++%4) {
			case 0:
				CommonUtil.move(card[i], card[i].getLocation(), new Point(90, 250+i*4));
				playerList[0].add(card[i]);
				break;
			case 1:
				CommonUtil.move(card[i], card[i].getLocation(), new Point(420+i*6, 510));
				playerList[1].add(card[i]);
				break;
			case 2:
				CommonUtil.move(card[i], card[i].getLocation(), new Point(810, 250+i*4));
				playerList[2].add(card[i]);
				break;
			case 3:
				CommonUtil.move(card[i], card[i].getLocation(), new Point(420+i*6, 50));
				playerList[3].add(card[i]);
				break;
			}
			container.setComponentZOrder(card[i], 0);
			count++;
		}
		if(this.t!=null) {
			this.t.isPublish = false;
		}
		for(int i=0;i<4;i++) {
			CommonUtil.cardSort(playerList[i]);
			CommonUtil.rePosition(playerList[i], i,this);
		}		
		if(bankerFlag==1) {
			container.setComponentZOrder(laid,0);
			laid.setVisible(true);
		}
		if(bankerFlag==1) {
			time[1].setVisible(true);			
		}
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		
		if(e.getSource()==exit) {
			this.dispose();
			System.exit(0);
		}
		if(e.getSource()==restart) {
			Constants.executor.execute(()-> Constants.SUBJECT_AUDIO.closePlay());
			thread.interrupt();
			thread.stop();
			thread=null;
			t=null;
			this.dispose();
			container.removeAll();
			//System.exit(0);
			for (int i=0;i<4;i++) {
				time[i].setVisible(false);
				playerList[i].clear();
			}
			int count =0;
			for(int i=1;i<=4;i++) {
				for(int j=1;j<=13;j++) {
					card[count]=null;
					count++;
				}
			}
			container.remove(jl);
			this.remove(container);
			try {
				Thread.sleep(500);
			} catch (InterruptedException ex) {
				ex.printStackTrace();
			}
			try {
				new GameMain();
			} catch (InterruptedException ex) {
				ex.printStackTrace();
			}
		}
		if(e.getSource()==openCard) {
			Constants.executor.execute(()->Constants.SEE_MAN_AUDIO.play());
			for(Card card : playerList[1]) {
				card.turnFront();
			}
			openFlag[1]=1;
			openCard.setVisible(false);			
		}
		if(e.getSource()==discard) {
			Constants.executor.execute(()->Constants.DISCARD_AUDIO.play());
			discard.setVisible(false);
			quitFlag[1]=1;
			quitCardIcon[1].setIcon(new ImageIcon("images/放弃.png"));
			container.setComponentZOrder(quitCardIcon[1],0);
			quitCardIcon[1].setVisible(true);
			addLaid.setVisible(false);
			followLaid.setVisible(false);
			compareCard.setVisible(false);
			openCard.setVisible(false);
			laid.setVisible(false);
			t.isRun=false;
			nextPlayer=true;
		}
		if(e.getSource()==laid) {
			laidIsClick=!laidIsClick;
			if(laidIsClick) {
				container.setComponentZOrder(goldPanel,0);
				goldPanel.setVisible(true);
			}else {
				goldPanel.setVisible(false);
			}	
		}
		if(e.getSource()==addLaid) {
			addlaidIsClick=!addlaidIsClick;
			if(addlaidIsClick) {
				container.setComponentZOrder(goldPanel,0);
				goldPanel.setVisible(true);
			}else {
				goldPanel.setVisible(false);
			}	
		}
		if(e.getSource()==followLaid) {
			Constants.executor.execute(()->Constants.FOLLOW_MAN_AUDIO.play());
			playerGold[1]-=initGold;	
			currPlayerGold[1]+=initGold;
			inigoldLabel[1].setText(""+currPlayerGold[1]);
			playergoldLabel[1].setText(""+playerGold[1]);
			t.isRun=false;
			followLaid.setVisible(false);
			nextPlayer=true;
		}
		if(e.getSource()==compareCard) {
			compareCardIsClick=!compareCardIsClick;
			for(int i=0;i<quitFlag.length;i++) {
				if (i!=1) {
					compareLabel[i].setVisible(false);
				}
				if(quitFlag[i]==0 && i!=1) {
					compareLabel[i].setVisible(true);
					compareLabel[i].addMouseListener(this);
				}
			}
			if (compareCardIsClick) {
				container.setComponentZOrder(comparePanel,0);
				comparePanel.setVisible(true);
			}else {
				comparePanel.setVisible(false);
			}
		}
	}
	public static void main(String[] args) throws InterruptedException {
		new GameMain();
	}
	...........
}

完成后启动main方法就可以了。
在这里插入图片描述
完整源码:
炸金花完整源码(含音效和图片等资源)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2108855.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

shell 中的grep sed awk命令

目录 一、grep命令 1.基本格式 2.常用命令 3. sort 命令 3.1 格式 3.2 常用选项 4. uniq 快捷去重 4.1 格式 5. tr 命令 5.1 格式 5.2 常用选项 练习&#xff1a; 二、sed 命令 1. sed基本概念 2. 基本操作格式 3. 常用选项 4. 应用 5. 文本模式过滤行内容 6. s…

C#自定义控件的放置与拖动

1、自定义控件 using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace PartA…

【mysql】mysql修改sql_mode之后无法启动

现象&#xff1a;修改后mysql无法启动&#xff0c;不报错 原因&#xff1a;MySQL在8以后sql_mode已经取消了NO_AUTO_CREATE_USER这个关键字。去掉这个关键字后&#xff0c;启动就可以了 修改前&#xff1a; sql_modeSTRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR…

jenkins 工具使用

使用方式 替代手动&#xff0c;自动化拉取、集成、构建、测试&#xff1b;是CI/CD持续集成、持续部署主流开发模式中重要的环节&#xff1b;必须组件 jenkins-gitlab&#xff0c;代码公共仓库服务器&#xff08;至少6G内存&#xff09;&#xff1b;jenkins-server&#xff0c;…

查看当前主机的硬盘是固态硬盘还是机械硬盘

windows主机下查看硬盘类型方法&#xff1a; 打开dos界面&#xff0c;输入 powershell进入powershell界面 在PowerShell窗口中&#xff0c;输入 Get-PhysicalDisk 命令并按回车。 发现MediaType下面的值为HDD,即为机械硬盘&#xff0c;如果是固态硬盘&#xff0c;则为SSD

什么是CDN及其如何影响SEO?

有没有想过&#xff0c;为什么你的网站在谷歌搜索结果的后几页徘徊&#xff0c;即使你已经优化了每一个网页&#xff1f; 有时候&#xff0c; 慢速的网站性能可能是罪魁祸首。 如果这个问题引起了你的共鸣&#xff0c;那么你可能想要探索一下内容分发网络&#xff08;Content…

Android平台通过RTSP服务实现摄像头麦克风共享

技术背景 前些年&#xff0c;我们在完成Android平台RTMP直播推送模块后&#xff0c;遇到这样的技术需求&#xff0c;好多开发者希望在Android平台&#xff0c;实现摄像头和麦克风音视频数据采集编码打包后&#xff0c;对外提供RTSP&#xff08;Real Time Streaming Protocol&a…

【DEV工具-IDEA】新建springboot项目,无法选择java8?

问题&#xff1a;新建springboot项目&#xff0c;无法选择java8。 #解决&#xff1a; 替换为 &#xff1a;https://start.aliyun.com

基于蜣螂优化最小二乘支持向量机的数据分类预测Matlab程序DBO-LSSVM 多特征输入多类别输出 含基础程序

基于蜣螂优化最小二乘支持向量机的数据分类预测Matlab程序DBO-LSSVM 多特征输入多类别输出 含基础程序 文章目录 一、基本原理DBO&#xff08;Dung Beetle Optimization&#xff09;算法原理LSSVM&#xff08;Least Squares Support Vector Machine&#xff09;模型原理DBO-LSS…

【C#跨平台开发详解】C#跨平台开发技术之.NET Core基础学习及快速入门

1. C#与.NET的发展历程 C#是由Microsoft开发的现代编程语言&#xff0c;最初伴随着.NET Framework发布。随着技术的进步&#xff0c;特别是针对跨平台开发的需求&#xff0c;Microsoft推出了.NET Core&#xff0c;这是一个开源且跨平台的框架&#xff0c;支持Windows、macOS和…

微信小程序手写签名

微信小程序手写签名组件 该组件基于signature_pad封装&#xff0c;signature_pad本身是web端的插件&#xff0c;此处将插件代码修改为小程序端可用。 signature_pad.js /*!* Signature Pad v5.0.3 | https://github.com/szimek/signature_pad* (c) 2024 Szymon Nowak | Releas…

Windows10 安全加固之禁止光驱、U盘等自动播放

在使用Windows10系统的电脑中插入插入光盘或者U盘时,默认是自动播放的,这样会引入一些可能不安全的因素。因此,为了系统安全,有必要禁止光驱、U盘等自动播放。具体方法如下: 方法一:通过设置页面关闭 第1步:单击win10系统的“开始”菜单->“设置”,打开“windows设…

算法:区间dp

文章目录 一、适用场景二、基本思路步骤时间复杂度&#xff1a; 三、例题 区间动态规划&#xff08;Interval DP&#xff09;是一种用于解决某些需要处理区间或子段问题的动态规划方法&#xff0c;特别适合于问题的解可以通过子区间的解进行组合的情况。该方法的核心思想是在子…

pico手柄和人物模型手部旋转同步,实现手柄控制手臂手部位置移动、手部旋转和手指的操作了

这里的主要内容就是下述代码&#xff1b; // 获取左手控制器的旋转&#xff08;四元数表示&#xff09;Quaternion aRotationQuaternion leftHandController.rotation;// 计算旋转差值&#xff08;四元数表示&#xff09;Quaternion rotationDifference Quaternion.Euler(0, …

Qt创建项目及相关问题

文章目录 1. Qt项目创建2. 认识项目代码main.cppwidget.hwidget.cppwidget.ui.pro构建过程生成的中间文件 3. Hello World程序图形化方式创建代码方式创建内存泄漏问题编辑框方式创建按钮方式创建 4. 对象树引入对象树原因对象树自动释放对象实验演示 5. 乱码问题 1. Qt项目创建…

Databend 产品月报(2024年8月)

很高兴为您带来 Databend 2024 年 8 月的最新更新、新功能和改进&#xff01;我们希望这些增强功能对您有所帮助&#xff0c;并期待您的反馈。 Kafka Connect Sink Connector 插件 我们推出了一种将 Kafka 连接到 Databend 的新方式&#xff1a;databend-kafka-connect&#…

2023Idea版本无法下载通义灵码插件以及无法登录问题

进入下载插件处 在插件主页安装时&#xff0c;通常会根据当前自己访问的IDEA版本推荐合适的插件版本&#xff0c;所以最终会安装成功 idea中通义灵码插件无法登录问题

书客、松下、飞利浦护眼台灯怎么样?测评寻找护眼台灯天花板!

大家好&#xff0c;我是专注在护眼领域的一名评测师&#xff0c;长期以来&#xff0c;我致力于探索并体验各类能保护视力健康的护眼产品。今天&#xff0c;我来和大家分享我对护眼台灯的深入评测。护眼台灯作为日常学习生活的一部分&#xff0c;视觉体验的好坏往往取决于所选用…

Pygame中获取鼠标按键状态的方法

在《Pygame中获取鼠标位置的方法》中提到&#xff0c;可以通过鼠标事件和mouse模块中的函数获取鼠标位置&#xff0c;这两种方法同样适用于获取鼠标按键状态。 1 通过鼠标点击事件获取鼠标按键状态 通过鼠标点击事件获取鼠标按键状态的代码如图1所示。 图1 鼠标点击事件获取鼠…

HRGraph: 利用大型语言模型(LLMs)构建基于信息传播的HR数据知识图谱与职位推荐

知识图谱&#xff08;KGs&#xff09;作为语义网络&#xff0c;在管理不同领域复杂互联数据方面表现出极高的有效性&#xff0c;通过提供统一、上下文化和结构化的表示&#xff0c;具有灵活性&#xff0c;能够轻松适应不断发展的知识。在处理复杂的人力资源&#xff08;HR&…