ROTAZIONE POLIGONO
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
import java.awt.geom.*;
public class RotazionePoligono extends Applet implements MouseListener, KeyListener{
private int[] xpoints={0,-10,-7,7,10};
private int[] ypoints={-10,-2,10,10,-2};
private Polygon poly;
int rotation=0;
public void init(){
poly=new Polygon(xpoints,ypoints,xpoints.length);
addMouseListener(this);
addKeyListener (this);}
public void paint (Graphics g) {Graphics2D
G2D = (Graphics2D) g;
int width = getSize (). Width;
int height = getSize (). Height;
g2d.setColor (Color.black);
g2d.fillRect (0.0, width, height);
g2d.translate (width / 2, height / 2);
g2d.scale (20:20);
g2d.rotate (Math . toRadians (rotation));
g2d.setColor (Color.Red);
g2d.draw (poly);
g2d.setColor (Color.Blue)
g2d.fill (poly);}
public void mouseEntered ( MouseEvent m) {} public
void mouseExited(MouseEvent m){}
public void mouseReleased(MouseEvent m){}
public void mouseClicked(MouseEvent m){}
public void mousePressed(MouseEvent m){
switch(m.getButton()){
case MouseEvent.BUTTON1:
rotation--;
if(rotation <0) rotation="359;"> 360) rotation=0;
repaint();
break;
}
}
public void keyReleased(KeyEvent k){}
public void keyTyped(KeyEvent k){}
public void keyPressed(KeyEvent k){
switch(k.getKeyCode()){
case KeyEvent.VK_LEFT:
rotation--;
if(rotation <0) rotation="359;"> 360) rotation=0;
repaint();
break;
}
}
}
Quickpost this image to Myspace, Digg, Facebook, and others!
import java.awt.event.*;
import java.applet.*;
import java.util.*;
import java.awt.geom.*;
public class RotazionePoligono extends Applet implements MouseListener, KeyListener{
private int[] xpoints={0,-10,-7,7,10};
private int[] ypoints={-10,-2,10,10,-2};
private Polygon poly;
int rotation=0;
public void init(){
poly=new Polygon(xpoints,ypoints,xpoints.length);
addMouseListener(this);
addKeyListener (this);}
public void paint (Graphics g) {Graphics2D
G2D = (Graphics2D) g;
int width = getSize (). Width;
int height = getSize (). Height;
g2d.setColor (Color.black);
g2d.fillRect (0.0, width, height);
g2d.translate (width / 2, height / 2);
g2d.scale (20:20);
g2d.rotate (Math . toRadians (rotation));
g2d.setColor (Color.Red);
g2d.draw (poly);
g2d.setColor (Color.Blue)
g2d.fill (poly);}
public void mouseEntered ( MouseEvent m) {} public
void mouseExited(MouseEvent m){}
public void mouseReleased(MouseEvent m){}
public void mouseClicked(MouseEvent m){}
public void mousePressed(MouseEvent m){
switch(m.getButton()){
case MouseEvent.BUTTON1:
rotation--;
if(rotation <0) rotation="359;"> 360) rotation=0;
repaint();
break;
}
}
public void keyReleased(KeyEvent k){}
public void keyTyped(KeyEvent k){}
public void keyPressed(KeyEvent k){
switch(k.getKeyCode()){
case KeyEvent.VK_LEFT:
rotation--;
if(rotation <0) rotation="359;"> 360) rotation=0;
repaint();
break;
}
}
}
Quickpost this image to Myspace, Digg, Facebook, and others!