Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
Octagon.java
Package: Octagon.rar [view]
Upload User: topwell
Upload Date: 2022-05-30
Package Size: 1k
Code Size: 1k
Category:
WinSock-NDIS
Development Platform:
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);
- }
- }