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

📄 testarcs.java

📁 此源码为机械工业出版社出版的《Java语言程序设计》第三版所配套的书中所有源代码。
💻 JAVA
字号:
// TestArcs.java: Demonstrate drawing arcs
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;

public class TestArcs extends JFrame
{
  // Default constructor
  public TestArcs()
  {
    setTitle("Show Arcs");
    getContentPane().add(new ArcsPanel());
  }

  // Main method
  public static void main(String[] args)
  {
    TestArcs frame = new TestArcs();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(250, 300);
    frame.setVisible(true);
  }
}

// The class for drawing arcs on a panel
class ArcsPanel extends JPanel
{
  // Draw four blazes of a fan
  public void paintComponent(Graphics g)
  {
    super.paintComponent(g);

    int xCenter = getWidth()/2;
    int yCenter = getHeight()/2;
    int radius =
      (int)(Math.min(getSize().width, getSize().height)*0.4);

    int x = xCenter - radius;
    int y = yCenter - radius;

    g.fillArc(x, y, 2*radius, 2*radius, 0, 30);
    g.fillArc(x, y, 2*radius, 2*radius, 90, 30);
    g.fillArc(x, y, 2*radius, 2*radius, 180, 30);
    g.fillArc(x, y, 2*radius, 2*radius, 270, 30);
  }
}

⌨️ 快捷键说明

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