zoukankan      html  css  js  c++  java
  • 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、运行后效果

  • 相关阅读:
    HDU 1969 Pie(二分查找)
    HDU 1896 Stones (优先队列)
    HDU 1548 A strange lift(BFS)
    HDU 1518 Square(DFS)
    CDOJ1085 基爷与加法等式 爆搜DFS
    Codeforces Round #245 (Div. 2) C. Xor-tree DFS
    Codeforces ZeptoLab Code Rush 2015 B. Om Nom and Dark Park DFS
    Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索
    Codeforces Round #401 (Div. 2)A B C
    Codeforces Round #297 (Div. 2)D. Arthur and Walls 搜索bfs
  • 原文地址:https://www.cnblogs.com/laixiaolian/p/5731189.html
Copyright © 2011-2022 走看看