问题描述
想要那种可以用鼠标点的格子,格子里还要是数字要做这样的界面的话又需要几个类呢?我是一只小白对java还不是熟悉就详细解释先谢谢了qwq
解决方案
解决方案二:
packagecom.suzhw.stu.swing.jframe.demo;importjava.awt.Container;importjava.awt.GridLayout;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.WindowConstants;/***JFrame中放一个九宫格,每个格子可点击,并含数字*/publicclassSudokuInJFrameDemoextendsJFrame{/****/privatestaticfinallongserialVersionUID=1L;publicSudokuInJFrameDemo(){setTitle("九宫格按钮");setSize(210,210);setVisible(true);setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);Containerc=getContentPane();GridLayoutgridLayout=newGridLayout(3,3);c.setLayout(gridLayout);JButtonjbut=null;for(inti=1;i<10;i++){jbut=newJButton(String.valueOf(i));c.add(jbut);}}publicstaticvoidmain(String[]args){newSudokuInJFrameDemo();}}