Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 5:10 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: Polygon in Java
PostPosted: Tue Nov 11, 2008 8:42 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

Draw Polygon in Java
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class DrawPolygon extends JPanel {
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
  g.setColor(Color.red);
     Polygon polygon1= new Polygon();
     for (int i = 0; i < 3; i++){
      polygon1.addPoint((int) (40 + 50 * Math.cos(i * 2 * Math.PI / 3)),
          (int) (150 + 50 * Math.sin(i * 2 * Math.PI / 3)));
   }
   g.drawPolygon(polygon1);

     Polygon polygon2= new Polygon();
     for (int i = 0; i < 6; i++){
      polygon2.addPoint((int) (160 + 50 * Math.cos(i * 2 * Math.PI / 6)),
          (int) (150 + 50 * Math.sin(i * 2 * Math.PI / 6)));
   }
   g.drawPolygon(polygon2);

    Polygon polygon3 = new Polygon();
   
     for (int i = 0; i < 360; i++) {
      double value = i / 360.0;
      polygon3.addPoint((int) (290 + 50 * value * Math.cos(8 * value * Math.PI)),
          (int) (150 + 50 * value * Math.sin(8 * value * Math.PI)));
   }
      g.drawPolygon(polygon3);
   }
   
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setTitle("Show Different Polygons");
    frame.setSize(350, 250);
    Container contentPane = frame.getContentPane();
    contentPane.add(new DrawPolygon());
    frame.show();
  }
}


Attachments:
File comment: draw polygon in Java
polygon.gif
polygon.gif [ 6.24 KiB | Viewed 7535 times ]

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 video chat application in java
 navigating to database using java
 java mobile apps
 need help in java
 Read your gmail using Java code
 Java Programing to communicating port parallel
 Java Chat
 Steganography in java
 java code for listing folder contents from remote folder
 java

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: Google Adsense [Bot] and 3 guests



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team