- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
Octagon.java
资源名称:Octagon.rar [点击查看]
上传用户:topwell
上传日期:2022-05-30
资源大小:1k
文件大小:1k
源码类别:
网络编程
开发平台:
DOS
- import java.awt.*;
- import javax.swing.*;
- public class Octagon extends JFrame{
- public Octagon(){
- add(new OctagonPanel());
- }
- public static void main(String[] args){
- Octagon frame = new Octagon();
- frame.setTitle("Octagon");
- frame.setLocationRelativeTo(null);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(300, 300);
- frame.setVisible(true);
- }
- }
- class OctagonPanel extends JPanel{
- protected void paintComponent(Graphics g){
- super.paintComponent(g);
- //Get the center point and radius
- int xCenter = getSize().width / 2;
- int yCenter = getSize().height / 2;
- int radius = (Math.min(xCenter, yCenter) - 20);
- System.out.println("xCenter = " + xCenter + ", yCenter = " + yCenter +
- ", radius = " + radius);
- Polygon octagon = new Polygon();
- for(int i = 0; i < 8; i++){
- double angle = Math.PI * i * 45.0 / 180;
- int x = (int)(xCenter - radius * Math.cos(angle));
- int y = (int)(yCenter - radius * Math.sin(angle));
- octagon.addPoint(x, y);
- System.out.println("x = " + x + ", y = " + y);
- }
- // Draw a octagon
- g.drawPolygon(octagon);
- }
- }