⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exercise11_21.java

📁 Introduction to java programming 一书中所有编程练习部分的源码
💻 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 + -