棋盘小程序
今天偶尔闲下来,手生了,写个小程序熟悉熟悉:
Alltest程序中:
package supermarket;import java.io.FileNotFoundException;//import supermarket.TestPeople;public class Alltest {public static void main(String[] args) throws FileNotFoundException{ ShuiXianHuaShu t1 = new ShuiXianHuaShu(); // t1.number(); // t1.number2(); // Son a = new Son(); // InputOfOutput b2 = new InputOfOutput(); // b2.testInputOfOutput(); FangXing2 ss = new FangXing2(); ss.fangxing();}}
另一个文件代码
package supermarket;import java.awt.Color;import javax.swing.JFrame; import javax.swing.JLabel;/*** @author 用窗体展现国际象棋的棋盘*/ public class FangXing2 {public static void fangxing() {JFrame frame = new JFrame("国际象棋");frame.setSize(415, 435);// 假设棋盘为20*20for (int i = 0; i < 20; i++) {for (int j = 0; j < 20; j++) {JLabel label = new JLabel();label.setSize(20, 20);label.setBackground(((i + j) % 2 == 0) ? Color.BLACK: Color.white);label.setLocation(20 * i, 20 * j);// 设置不透明,要不然不会显示label.setOpaque(true);frame.add(label);}}// 窗体居中显示frame.setLocationRelativeTo(null);// 当窗口关闭程序结束frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 展示棋盘frame.setVisible(true);} }
转载于:https://www.cnblogs.com/wzl629/p/9257323.html
总结
- 上一篇: git远端密码修改
- 下一篇: [LeetCode] 102. Bina