Skip navigation.
University » Corsi precedenti (it) » IGEA » 2005-06 » 03/04/06 » PannellOtello.java

File PannellOtello.java


import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
 
public class PannellOtello extends JPanel {
 
    public int[] pedineColonna;
    public int[] pedineRiga;
    public int nPedine; 
 
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d=(Graphics2D) g;
 
        /*
            Disegno dell'ellissi -- prima parte dell'esercitazione
 
            Ellipse2D.Double e=new Ellipse2D.Double(0,0,50,50);
            g2d.draw(e);
        */
 
        //Disegno della griglia
        int w=getWidth();
        int h=getHeight();
        int i;
        double w8=w/8.0;
        double h8=h/8.0;
        for(i=0; i<=8; i++) {
            Line2D.Double l=new Line2D.Double(i*w8, 0, i*w8, h);
            g2d.draw(l);
        }
        for(i=0; i<=8; i++) {
            Line2D.Double l=new Line2D.Double(0, i*h8, w, i*h8);
            g2d.draw(l);
        }
 
        //Disegno delle pedine
        for(i=0; i<nPedine; i++) {
            Ellipse2D.Double e=new Ellipse2D.Double(pedineColonna[i]*w8, pedineRiga[i]*h8, w8, h8);
            if(i%2==0)
                g2d.setColor(Color.blue);
            else
                g2d.setColor(new Color(Color.red));
            g2d.fill(e);
        }
 
    }
 
}