📄 exercise11_21.java
字号:
// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -