• java—连连看GUI


    1、连连看棋盘图形化

    package Link;
    
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.util.Random;
    
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    
    public class TestGUI extends JFrame {
    	ImageIcon imageIcon = new ImageIcon("Images/build/BackGround.jpg");
    	Image imageBackground = imageIcon.getImage();
    
    	static int arr[][] = new int[8][10];
    	
    	static{
    		Random random = new Random();
    		for (int i = 0; i < 20; i++) {
    			int count = 0;
    			while (count < 4) {
    				int x = random.nextInt(8);
    				int y = random.nextInt(10);
    				if (arr[x][y] == 0) {
    					arr[x][y] = i;
    					count++;
    				}
    			}
    		}
    	}
    
    	static Image[] chessImage = new Image[20];
    	static {
    		for (int i = 0; i < chessImage.length; i++) {
    			chessImage[i] = new ImageIcon("Images/build/" + (i + 1) + ".png").getImage();
    		}
    	}
    
    	public TestGUI() {
    		this.setTitle("连连看");// 设置 标题
    
    		this.setSize(1000, 650);// 设置宽高
    
    		this.setLocationRelativeTo(null);// 自动适配到屏幕中间
    
    		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置关闭模式
    		this.setVisible(true);// 设置可见
    
    		ImageIcon imageIcon = new ImageIcon("Images/build/biao.png");
    		Image image = imageIcon.getImage();
    		this.setIconImage(image);// 设置连连看窗体图标
    	}
    
    	@Override
    	public void paint(Graphics g) {
    		super.paint(g);
    
    		g.setColor(Color.green);
    		Font font = new Font("宋体", Font.BOLD, 28);
    		g.setFont(font); // 设置字体颜色和字体大小
    
    		g.drawImage(imageBackground, 0, 0, this);// 设置背景图片
    
    		g.drawString("连连看", 400, 100);
    
    		for (int i = 0; i < 8; i++) {
    			for (int j = 0; j < 10; j++) {
    				g.drawImage(chessImage[arr[i][j]], 200 + (j * 55), 150 + (i * 55), this);
    			}
    		}
    
    	}
    
    	public static void main(String[] args) {
    		
    		new TestGUI();
    
    	}
    }
    

    2、运行后效果

  • 相关阅读:
    Oracle 数据库连接很慢,服务器监听一直等待
    Maven 根据不同的环境使用不同的配置
    Maven 根据不同的包路径打出不同的Jar包
    Linux 安装Nginx并支持SSL
    Nginx OpenSSL创建自签证书实现HTTP转HTTPS
    Oracle 服务突然中断处理(检查状态、重启)
    请求转发和重定向
    PHP PDO的简单封装(使用命名空间方式)
    PHP PDO学习小结
    MYSQL预处理机制
  • 原文地址:https://www.cnblogs.com/laixiaolian/p/5731189.html
Copyright © 2020-2023  润新知