exercise11_21.java
来自「Introduction to java programming 一书中所有编程」· Java 代码 · 共 40 行
JAVA
40 行
// Exercise11_21.javaimport java.awt.*;import javax.swing.*;public class Exercise11_21 extends JFrame { public Exercise11_21() { Container container = getContentPane(); container.setLayout(new GridLayout(3, 3)); for (int i = 0; i < 9; i++) { container.add(new Cell()); } } public static void main(String[] args) { Exercise11_21 frame = new Exercise11_21(); frame.setTitle("Exercise11_21"); frame.setSize(400, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } class Cell extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); int mode = (int)(Math.random() * 3); if (mode == 0) { g.drawLine(10, 10, getWidth() - 10, getHeight() - 10); g.drawLine(getWidth() - 10, 10, 10, getHeight() - 10); } else if (mode == 1) { g.drawOval(10, 10, getWidth() - 20, getHeight() - 20); } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?