Lianliankan code implemented in java based on swing
The example in this article describes the implementation of Lianliankan code in Java based on swing. Share it with everyone for your reference.
The main function codes are as follows:
package llkan; import javax.swing.*; import java.awt.*; import java.awt.event.*; /** * 连连看游戏 * @author Administrator *2014年10月17日 */ public class MainGame implements ActionListener { JFrame mainFrame; // 主面板 Container thisContainer; JPanel centerPanel, southPanel, northPanel; // 子面板 JButton diamondsButton[][] = new JButton[6][5];// 游戏按钮数组 JButton exitButton, resetButton, newlyButton; // 退出,重列,重新开始按钮 JLabel fractionLable = new JLabel("0"); // 分数标签 JButton firstButton, secondButton; // 分别记录两次被选中的按钮 int grid[][] = new int[8][7];// 储存游戏按钮位置 static boolean pressInformation = false; // 判断是否有按钮被选中 int x0 = 0, y0 = 0, x = 0, y = 0, fristMsg = 0, secondMsg = 0, validateLV; // 游戏按钮的位置坐标 int i, j, k, n;// 消除方法控制 public void init() { mainFrame = new JFrame("连连看游戏"); thisContainer = mainFrame.getContentPane(); thisContainer.setLayout(new BorderLayout()); centerPanel = new JPanel(); southPanel = new JPanel(); northPanel = new JPanel(); thisContainer.add(centerPanel, "Center"); thisContainer.add(southPanel, "South"); thisContainer.add(northPanel, "North"); centerPanel.setLayout(new GridLayout(6, 5)); for (int cols = 0; cols < 6; cols++) { for (int rows = 0; rows < 5; rows++) { diamondsButton[cols][rows] = new JButton( String.valueOf(grid[cols + 1][rows + 1])); diamondsButton[cols][rows].addActionListener(this); centerPanel.add(diamondsButton[cols][rows]); } } exitButton = new JButton("退出"); exitButton.addActionListener(this); resetButton = new JButton("重列"); resetButton.addActionListener(this); newlyButton = new JButton("再来一局"); newlyButton.addActionListener(this); southPanel.add(exitButton); southPanel.add(resetButton); southPanel.add(newlyButton); fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable .getText()))); northPanel.add(fractionLable); mainFrame.setBounds(280, 100, 500, 450); mainFrame.setVisible(true); }
The above is the content of Lianliankan code implemented in java based on swing. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Square Root in Java. Here we discuss how Square Root works in Java with example and its code implementation respectively.

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to the Armstrong Number in Java. Here we discuss an introduction to Armstrong's number in java along with some of the code.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is
