exercise11_5.java

来自「java程序设计 机械工业出版社 书籍代码」· Java 代码 · 共 38 行

JAVA
38
字号
// Exercise11_5.java:import javax.swing.*;import java.awt.*;public class Exercise11_5 extends JFrame {  /** Default constructor */  public Exercise11_5() {    // Set the window title    setTitle("Exercise11_5");    // Add buttons to the frame    getContentPane().add(new Grid());  }  /** Main method */  public static void main(String[] args) {    Exercise11_5 frame = new Exercise11_5();    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    frame.setSize(100, 80);    frame.setVisible(true);  }}class Grid extends JPanel {  protected void paintComponent(Graphics g) {    super.paintComponent(g);    g.setColor(Color.red);    g.drawLine(getWidth() / 3, 0, getWidth() / 3, getHeight());    g.drawLine(getWidth() * 2 / 3, 0, getWidth() * 2 / 3, getHeight());    g.setColor(Color.blue);    g.drawLine(0, getHeight() / 3, getWidth(), getHeight() / 3);    g.drawLine(0, getHeight() * 2 / 3, getWidth(), getHeight() * 2 / 3);  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?