1. Lezione del 21 novembre 2008 per la classe IV A Liceo tecnico Prof. Silvano natalizi
2.
3.
4.
5.
6.
7.
8.
9.
10. Il metodo paint() public void paint(Graphics g) { //create an instance of Graphics2D Graphics2D g2d = (Graphics2D) g; //create a random number Random rand = new Random(); //save the window width/height int width = getSize().width; int height = getSize().height; //fill the background with black g2d.setColor(Color.BLACK); g2d.fillRect(0, 0, width, height); //move, rotate, and scale the shape randomly g2d.translate(width / 2, height / 2); g2d.scale(20, 20); g2d.rotate(Math.toRadians(rotation)); //draw the shape with a random color g2d.setColor(Color.RED); g2d.fill(poly); g2d.setColor(Color.BLUE); g2d.draw(poly); }
11. Elaborazione degli eventi del mouse //handle mouse events 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; repaint(); break; case MouseEvent.BUTTON3: rotation++; if (rotation > 360) rotation = 0; repaint(); break; } } }