Total members 11891 |It is currently Wed Jul 17, 2024 12:07 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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 03i++){
      
polygon1.addPoint((int) (40 50 Math.cos(Math.PI 3)),
          (int) (
150 50 Math.sin(Math.PI 3)));
   }
   
g.drawPolygon(polygon1);

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

    
Polygon polygon3 = new Polygon();
   
     for (
int i 0360i++) {
      
double value 360.0;
      
polygon3.addPoint((int) (290 50 value Math.cos(value Math.PI)),
          (int) (
150 50 value Math.sin(value Math.PI)));
   }
      
g.drawPolygon(polygon3);
   }
   
  public static 
void main(String[] args) {
    
JFrame frame = new JFrame();
    
frame.setTitle("Show Different Polygons");
    
frame.setSize(350250);
    
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 17566 times ]

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Polygon in Java
 Drawing a Polygon in php     -  
 how to attach a texture to polygon     -  
 Draw Oval,Arc,Polygon,string,Line,Round and 3D Rectangle     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 Java course     -  
 What is Java API?!!!     -  
 java or .net     -  
 need help in java     -  
 Using FTP in java     -  
 what is java     -  



Topic Tags

Java Graphics






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com