怎么用java编下面的程序,最好快点,而且不要用图形界面生成的代码!!!
- 提问者网友:献世佛
- 2021-07-19 00:24
- 五星知识达人网友:空山清雨
- 2021-07-19 01:56
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Classroom extends JFrame {
private final int DESK_NUMBER = 36; //桌子数目
private final int ROW = 7; //行数
private final int COL = 5; //列数
private JButton button[];
private JPanel classPanel;
public Classroom() {
button = new JButton[DESK_NUMBER];
classPanel = new JPanel();
this.setLayout(new BorderLayout());
classPanel.setLayout(new GridLayout(ROW, COL));
button[0] = new JButton("讲台");
for(int i=1; i<=DESK_NUMBER-1; i++) {
button[i] = new JButton("座位"+i);
classPanel.add(button[i]);
}
this.add(button[0], BorderLayout.NORTH);
this.add(classPanel, BorderLayout.CENTER);
this.setVisible(true);
this.pack();
}
public static void main(String[] args) {
new Classroom();
}
}