<pre>import javax.swing.*; import java.awt.*; public class Board extends JFrame { static final int Col=9; static final int Raw=9; public Board(String title) { super(title); setVisible(true); setSize(300,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); InitBoard(); } public void InitBoard() { Board b; Button[][] myboard=new Button[Raw][Col]; Panel p =new Panel(); p.setLayout(new GridLayout(Raw,Col)); for (int i=0; i<Col;i++) { for (int j=0; j<Raw; j++) { ImageIcon ic = new ImageIcon("mine.png"); Image im=ic.getImage(); myboard[i][j]= new Button(im); p.add(myboard[i][j]); add(p); } } } public static void main(String[] args) { new Board("Minesweeper"); }
import java.awt.*; import javax.swing.*; public class Button extends JButton { private Image img; public Button(Image img) { this.img = img; } public Image getIm() { return this.img; } public void SetIm(Image im) { this.img=im; } public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(img, 0, 0, getWidth(), getHeight(),null); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)