tomski
Messages postés
48
Date d'inscription
mercredi 24 mars 2004
Statut
Membre
Dernière intervention
24 décembre 2009
24 déc. 2009 à 20:36
UP
jarrive a dessiner un polygone a main levee, mais il ne sarrete pas, a chaque clic il cree un point....
jarrive toujours pas a supprimer le polygone que je selectionne, ni a le drag/drop, ni a le redimensionner.
Un petit coup de main, car la vraiment jai epuise toutes mes cartouches...
je poste mon code:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.Graphics.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.Properties;
import java.util.*;
import java.util.Calendar;
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.Writer;
import java.math.*;
import java.awt.geom.*;
import java.awt.geom.AffineTransform;
public class MACLASSE extends JFrame implements MouseListener{
static Toolkit toolkit = Toolkit.getDefaultToolkit();
static Dimension screenSize = toolkit.getScreenSize();
static int centerscreenW= screenSize.width / 2;
static int centerscreenH= screenSize.height / 2;
static int screenW= screenSize.width / 2;
static int screenH= screenSize.height / 2;
static int relocx = centerscreenW +50;
static int relocy = centerscreenH +50;
static int x;
static int y;
static int centreFx;
static int centreFy;
static String chaine="";
static String typedText;
static JLabel[] labelString;
static JLabel[] labelint;
static String[] arrayString;
static int[] arrayint;
static Polygon polygon;
JPanel titlePanel = new JPanel();
JPanel colorPanel = new JPanel();
JPanel lstPanel = new JPanel();
JLabel ls1 = new JLabel("Add Items to the Graph");
JLabel ls2 = new JLabel("Available Items");
DefaultListModel model = new DefaultListModel();
JList lst1, lst2;
JDialog d;
int pos;
int gotx;
int goty;
static int nbligne;
static JPanel pbuttons = new JPanel();
JPanel p_rotate = new JPanel();
JButton btn_rotate = new JButton("Rotate");
JButton btn_add = new JButton("Add");
JTextField txt_rotate = new JTextField();
JTextField txt_dept = new JTextField();
JTextField txt_size = new JTextField();
JTextField txt_num_shadow = new JTextField();
String[] array_house ={"Square", "Rectangle", "Circle", "Polygon"};
JList ls_house, ls_shadow, ls_orientation, ls_panel;
String[] array_shadow ={"Building", "Tree"};
String[] array_orientation ={"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSO", "SO", "OSO", "O", "ONO", "NO", "NNO"};
String[] array_panel ={"REC-210AE", "SHARP", "SUNTECH-STP175S", "SUNTECH-STP225", "TENESOL-TE2000-200"};
JScrollPane sc1, sc2, sc3, sc4;
double latitude;//48,52
double longitude;
double sun_height, sun_azimut;
double[] array_declinaison= {-20.8, -12.7, -1.9, 9.9, 18.9, 23.1, 21.3, 13.7, 3.0, -8.8, -18.4, -23.0};
//voir cours solaire
//double GHA; //GreenWich Hour Angle (angle horaire)
double panel_surface;
double solar_hour;
int real_solar_hour;//hsv
boolean hiver = true; //on est en hiver
boolean ouest = true; //on est a l'ouest
String dept;
static JPanel empty= new JPanel();
String[] elements1;
String ligne1, li1;
ArrayList<String> myArr = new ArrayList<String>();
ArrayList<String> myArr2 = new ArrayList<String>();
ArrayList<String> myArr3 = new ArrayList<String>();
ArrayList<String> myArr4 = new ArrayList<String>();
static ArrayList lspoly= new ArrayList();
static ArrayList mespoints= new ArrayList();
int index=0;
int year;
int month;
int date;
int hours;
int minutes;
int seconds;
//double dec;
//double hoehe;
double azimut;
double azimutA, azimutB, azimutC, azimutD;
double heightA, heightB, heightC, heightD;
double angleA, angleB, angleC, angleD;
double deltaA, deltaB, deltaC, deltaD;
double ecart_sud;
double total_distance;
double real_height;
double neighbour_height;
int converted_hour;
double Longueur, Largeur;
static boolean rotate, add;
static double angle;
int count;
Point mouseStart;
static Polygon shape;
static Polygon monpoly;
int xDragg, yDragg, xPosition, yPosition;
boolean moving = false;
//Highest quality of image
static RenderingHints renderHints;
static int longueur;
static double radians = 0.0;
static double cos = 1.0;
static double sin= 0.0;
static int angle_a, cx, cy;
static Graphics gBuffer;
static int form;
static Polygon[] array_polygon;
static Point[] array_point;
//int[] xCoord = new int[500];
//int[] yCoord = new int[500];
//int pointCt = 0;
//Point[] mespoints;
//public int locOffset;
//tableau multirectionnel: 1er {} janvier, 2nd {} fevrier
//1er{15 premiers jours, 15 derniersjours}
/*
double[][] correction_equation_of_time = {
{Double.parseDouble("-3,22"), Double.parseDouble("-9,12")},
{Double.parseDouble("-13,38"), Double.parseDouble("-14,27")},
{Double.parseDouble("-12,47"), Double.parseDouble("-9,16")}
};
*/
/*
vx=x*Math.cos()
vy = y*Math.sin();
*/
public void transform(Graphics2D g2d, double XTranslation, double YTranslation, double rotation){
g2d.translate(XTranslation, YTranslation);
g2d.rotate(rotation);
}
public MACLASSE(){
renderHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
renderHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
ls_orientation = new JList(array_orientation);
ls_panel = new JList(array_panel);
ls_shadow = new JList(array_shadow);
ls_house = new JList(array_house);
ListSelectionListener orientation_listener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent listSelectionEvent) {
//Object selectedOrientationValues[] = ls_orientation.getSelectedValues();
int selectionsOrientation[] = ls_orientation.getSelectedIndices();
for (int i=0; i<selectionsOrientation.length; i++){
switch(selectionsOrientation[i]){
case 0:angle 0.0; rotate true; break;
case 1:angle 22.5; rotate true; break;
case 2:angle 45.0; rotate true; break;
case 3:angle 67.5; rotate true; break;
case 4:angle 90.0; rotate true; break;
case 5:angle 112.5; rotate true; break;
case 6:angle 135.0; rotate true; break;
case 7:angle 157.5; rotate true; break;
case 8:angle 180.0; rotate true; break;
case 9:angle 202.5; rotate true; break;
case 10:angle 225.0; rotate true; break;
case 11:angle 247.5; rotate true; break;
case 12:angle 270.0; rotate true; break;
case 13:angle 292.5; rotate true; break;
case 14:angle 315.0; rotate true; break;
case 15:angle 337.5; rotate true; break;
case 16:angle 360.0; rotate true; break;
}
}
}
};
ListSelectionListener panel_listener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent listSelectionEvent) {
//Object selectedPanelValues[] = ls_panel.getSelectedValues();
int selectionsPanel[] = ls_panel.getSelectedIndices();
for (int i=0; i<selectionsPanel.length; i++){
switch(selectionsPanel[i]){
case 0:Longueur 1.665; Largeur 0.991;calc_surface(calc_cote(Largeur), Longueur);break;
case 1:Longueur 1.409; Largeur 1.009;calc_surface(calc_cote(Largeur), Longueur);break;
case 2:Longueur 1.580; Largeur 0.808;calc_surface(calc_cote(Largeur), Longueur);break;
case 3:Longueur 1.665; Largeur 0.991;calc_surface(calc_cote(Largeur), Longueur);break;
case 4:Longueur 1.507; Largeur 0.994;calc_surface(calc_cote(Largeur), Longueur);break;
}
}
}
};
ListSelectionListener shadow_listener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent listSelectionEvent) {
//Object selectedShadowValues[] = ls_shadow.getSelectedValues();
int selectionsShadow[] = ls_shadow.getSelectedIndices();
count = count+1;//pour connaitre ne nombre d'objets crees
}
};
ListSelectionListener house_listener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent listSelectionEvent) {
//Object selectedHouseValues[] = ls_house.getSelectedValues();
int selectionsHouse[] = ls_house.getSelectedIndices();
for (int i=0; i<selectionsHouse.length; i++){
switch(selectionsHouse[i]){
case 0:form = 0;break;
case 1:form = 1;break;
case 2:form = 2;break;
case 3:form = 3;break;
}
repaint();
}
}
};
ls_orientation.addListSelectionListener(orientation_listener);
ls_panel.addListSelectionListener(panel_listener);
ls_shadow.addListSelectionListener(shadow_listener);
ls_house.addListSelectionListener(house_listener);
btn_rotate.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("in BTN Rotate");
rotate = true;
//rotate = true;
if (txt_size.getText() != "" || txt_size.getText() != null){
longueur = Integer.parseInt(txt_size.getText());
}else{
}
angle = Double.parseDouble(txt_rotate.getText());
System.out.println("angle = "+ Double.toString(angle));
//polygon = rotate(shape, angle);
repaint();
}
});
btn_add.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
add = true;
}
});
pbuttons.setLayout(new GridLayout(20,1));
ls_house.setVisibleRowCount(1);
ls_shadow.setVisibleRowCount(1);
ls_orientation.setVisibleRowCount(1);
ls_panel.setVisibleRowCount(1);
sc1 = new JScrollPane(ls_house);
sc2 = new JScrollPane(ls_shadow);
sc3 = new JScrollPane(ls_orientation);
sc4 = new JScrollPane(ls_panel);
pbuttons.add(new JLabel("Departement"));
pbuttons.add(txt_dept);
pbuttons.add(new JLabel("Type of house:"));
pbuttons.add(sc1);
pbuttons.add(new JLabel("Size:"));
pbuttons.add(txt_size);
pbuttons.add(new JLabel("Orientation:"));
pbuttons.add(sc3);
pbuttons.add(new JLabel("Type of panel:"));
pbuttons.add(sc4);
pbuttons.add(new JLabel("Number of possible shadows:"));
pbuttons.add(txt_num_shadow);//num_shadow = nb of polygons to create
pbuttons.add(new JLabel("Type of shadow:"));
pbuttons.add(sc2);
pbuttons.add(btn_add);
pbuttons.add(new JLabel("Angle Rotation"));
pbuttons.add(txt_rotate);
pbuttons.add(btn_rotate);
empty.setLayout(new GridLayout(2,1));
//getContentPane();
//getContentPane().add(pbuttons);
System.out.println("in SUNSIM");
addMouseListener(this);
/*
addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e) {
if (mouseStart != null){
Point diff = new Point(e.getX()-mouseStart.x, e.getY()-mouseStart.y);
shape.translate(diff.x, diff.y);
repaint();
}
mouseStart = e.getPoint();
}
});
*/
sun_calc();
}//end GRAF()
public Polygon rotate(Polygon poly, double theta) {
Polygon newPoly;
int i;
double x, y;
// Return a new polygon by rotating the points in the given one.
newPoly = new Polygon();
for (i = 0; i < poly.npoints; i++) {
x = poly.xpoints[i] * Math.cos(theta)
+ poly.ypoints[i] * Math.sin(theta);
y = poly.ypoints[i] * Math.cos(theta)
- poly.xpoints[i] * Math.sin(theta);
newPoly.addPoint((int) x, (int) y);
}
return newPoly;
}
public static void main(String[] args) {
System.out.println("in MAIN");
MACLASSE sim = new MACLASSE();
sim.setSize(600,600);
sim.setTitle("SIMULATION");
//sim.setMenuBar();
ImageIcon img= new ImageIcon("smiley.gif");
sim.setIconImage(img.getImage());
//ajout du panel daffichage graphique
sim.getContentPane().add(BorderLayout.PAGE_START, empty);
sim.getContentPane().add(BorderLayout.LINE_START, pbuttons);
sim.getContentPane().add(BorderLayout.CENTER, new JPanel().add(new MyComponent()));
sim.getContentPane().add(BorderLayout.LINE_END, new JPanel());
sim.getContentPane().add(BorderLayout.PAGE_END, empty);
//sim.getContentPane().add(BorderLayout.CENTER, new MyComponent());
//sim.pack();
sim.setDefaultCloseOperation(EXIT_ON_CLOSE);
//Get the screen size
//Calculate the frame location
x = (screenSize.width - sim.getWidth()) / 2;
y = (screenSize.height - sim.getHeight()) / 2;
centreFx= sim.getWidth() / 2;
centreFy= sim.getHeight() / 2;
/*
labelString = new JLabel[10];
for(int i = 0; i < labelString.length; i++) {
labelString[i] = new JLabel("");
}
*/
//Set the new frame location
sim.setLocation(x, y);
sim.setVisible(true);
}//end main
public void readfile(String file){
System.out.println("in readfile()");
try{
System.out.println("in readfile.1st TRY");
//Reading the contents of the files
BufferedReader br1=new BufferedReader(new FileReader(file));
try{
System.out.println("in readfile.2nd TRY");
while ((ligne1=br1.readLine())!=null){
li1= ligne1;
elements1 = li1.split(";");
//ARRAYLIST
myArr.add(elements1[0]);
myArr2.add(elements1[1]);
myArr3.add(elements1[2]);
myArr4.add(elements1[3]);
System.out.println("myArr= "+myArr);
System.out.println("myArr2= "+myArr2);
System.out.println("myArr3= "+myArr3);
System.out.println("myArr4= "+myArr4);
System.out.println("elements1[0]= "+elements1[0]);
System.out.println("elements1.length= "+elements1.length);
System.out.println("elements1[1]= "+elements1[1]);
System.out.println("elements1.length= "+elements1.length);
System.out.println("elements1[2]= "+elements1[2]);
System.out.println("elements1.length= "+elements1.length);
System.out.println("elements1[3]= "+elements1[3]);
System.out.println("elements1.length= "+elements1.length);
index++;
nbligne++;
}//end while
}finally{
br1.close();
}
}catch(Exception e ){
System.out.println(e.toString());
System.out.println("PROBLEM HERE 1 = " + e.getMessage());
}//end try
//br1.close();
System.out.println("BR1 CLOSED");
}//end readfile
/****************************** END READFILE() ******************************************/
public void update(Graphics g){
paint(g);
//FINIR
}
static int rotate_y(int x, int y){
return ((int)(cy+y*cos+x*sin));
}
static int rotate_x(int x, int y){
return ((int)(cx+x*cos-y*sin));
}
static void SetAngle(double a){
radians = (a*2*Math.PI)/360;
cos = Math.cos(radians);
sin = Math.sin(radians);
}
static void RotatePolygon(int x[], int y[], int n){
int new_x[] = new int [n];
int new_y[] = new int [n];
for (int i=0; i<n; i++){
new_x[i]=rotate_x(x[i], y[i]);
new_y[i]=rotate_y(x[i], y[i]);
}
gBuffer.fillPolygon(new_x, new_y, n);
}
/*
static void drawStuff(){
int radius;
int x[];
int y[];
//Image Buffer = createImage(size().width, size().height);
//gBuffer = Buffer.getGraphics();
gBuffer = g;
//cx= size().width/2;
//cy = size().height/2;
cx = centreFx;
cy = centreFy;
//CARRE
radius = 60;
x= new int[4];
y= new int[4];
x[0] = radius;
x[1] = radius+50;
x[2] = radius+50;
x[3] = radius;
y[0] = -25;
y[1] = -25;
y[2] = 25;
y[3] = 25;
gBuffer.setColor(Color.magenta);
//dans le cas dun CARRE
RotatePolygon(x,y,4);
angle_a = 45;
SetAngle(angle_a);
}
*/
public void sun_calc(){
//get the month as an int: Jan = 1
Calendar c = Calendar.getInstance();
month = c.get(Calendar.MONTH);
//int day = c.get(Calendar.MONTH);
year = c.get(Calendar.YEAR);
date = c.get(Calendar.DATE);
hours = c.get(Calendar.HOUR);
minutes = c.get(Calendar.MINUTE);
seconds = c.get(Calendar.SECOND);
//real_solar_hour (hsv)
real_solar_hour= conversionHMS(hours, minutes, seconds);
System.out.println("real_solar_hour HMS= "+real_solar_hour);
//if (month between 21/09 and 21/03) = hiver else ete;
if (hiver == true){
//on retire 1h en hiver
real_solar_hour = real_solar_hour - 1*3600;
System.out.println("real_solar_hour HIVER= "+real_solar_hour);
}else{
//on retire 1h en hiver
real_solar_hour = real_solar_hour - 2*3600;
System.out.println("real_solar_hour ETE= "+real_solar_hour);
}
readfile("LongLat.txt");
if (txt_dept.getText() != null || txt_dept.getText()!=""){
dept = txt_dept.getText();
}else{
System.out.println("txt_dept.getText() == null OR EMPTY");
}
//ATTENTION: need get the longitude!!!
//keep the last two degrees and *4
if (longitude < 0.0){
ouest = true;
//-4mn a l'ouest
real_solar_hour = real_solar_hour - 4*60;
System.out.println("real_solar_hour WEST= "+real_solar_hour);
}else{
ouest = false;
//+4mn a l'est
real_solar_hour = real_solar_hour + 4*60;
System.out.println("real_solar_hour EAST= "+real_solar_hour);
}
//correction equation of time
if (date < 15){
switch (month){
case 0:real_solar_hour = real_solar_hour -(3*60)-22;break;
case 1:real_solar_hour = real_solar_hour -(13*60)-38;break;
case 2:real_solar_hour = real_solar_hour -(12*60)-47;break;
case 3:real_solar_hour = real_solar_hour -(3*60)-57;break;
case 4:real_solar_hour = real_solar_hour +(2*60)+58;break;
case 5:real_solar_hour = real_solar_hour +(2*60)+13;break;
case 6:real_solar_hour = real_solar_hour -(3*60)-23;break;
case 7:real_solar_hour = real_solar_hour -(6*60)-7;break;
case 8:real_solar_hour = real_solar_hour -27;break;
case 9:real_solar_hour = real_solar_hour +(10*60)+4;break;
case 10:real_solar_hour = real_solar_hour +(16*60)+25;break;
case 11:real_solar_hour = real_solar_hour +(11*60)+5;break;
}
System.out.println("real_solar_hour CORRECTED (DAY < 15) = "+real_solar_hour);
}else{
System.out.println("on est apres le 15");
switch (month){
case 0:real_solar_hour = real_solar_hour -(9*60)-12;break;
case 1:real_solar_hour = real_solar_hour -(14*60)-27;break;
case 2:real_solar_hour = real_solar_hour -(9*60)-16;break;
case 3:real_solar_hour = real_solar_hour +13;break;
case 4:real_solar_hour = real_solar_hour +(3*60)+39;break;
case 5:real_solar_hour = real_solar_hour +14;break;
case 6:real_solar_hour = real_solar_hour -(5*60)-28;break;
case 7:real_solar_hour = real_solar_hour -(4*60)-38;break;
case 8:real_solar_hour = real_solar_hour +(4*60)+20;break;
case 9:real_solar_hour = real_solar_hour +(14*60)+9;break;
case 10:real_solar_hour = real_solar_hour +(15*60)+25;break;
case 11:real_solar_hour = real_solar_hour +(5*60)+12;break;
}
System.out.println("real_solar_hour CORRECTED (DAY > 15) = "+real_solar_hour);
}
//azimut calculation
sun_azimut=Math.sin(latitude)*Math.cos(array_declinaison[month])*Math.cos(2)-Math.cos(latitude)*Math.sin(array_declinaison[month]);
sun_azimut= Math.cos(sun_azimut);
//sun height calculation
sun_height = Math.sin(latitude)*Math.sin(array_declinaison[month])+Math.cos(latitude)*Math.cos(array_declinaison[month])*Math.cos(2);
sun_height = Math.sin(sun_height);
real_height = sun_height;//change!
heightA = Math.atan(neighbour_height / total_distance);
//deltaA = delta entre point A et centre du panneau
angleA = Math.atan(deltaA / total_distance);
azimutA = -(angleA+ecart_sud); //sign - car soleil se leve a l'est
int browserOffset = c.get(Calendar.ZONE_OFFSET);
//this.browserOffset = date.getTimezoneOffset();
browserOffset = -browserOffset / 60;
int locOffset = browserOffset;
System.out.println("Latitude = "+Double.toString(latitude));
System.out.println("Longitude = "+Double.toString(longitude));
System.out.println("date = "+Integer.toString(date));
System.out.println("month = "+Integer.toString(month));
System.out.println("year = "+Integer.toString(year));
System.out.println("hours = "+Integer.toString(hours));
System.out.println("minutes = "+Integer.toString(minutes));
System.out.println("seconds = "+Integer.toString(seconds));
System.out.println("Mon_AZIMUT = "+Double.toString(sun_azimut));
//System.out.println("Juergen_AZIMUT = = "+Double.toString(azimut));
System.out.println("Ma_HAUTEUR = "+Double.toString(sun_height));
System.out.println("HAUTEUR_A = "+Double.toString(heightA));
System.out.println("ANGLE_A = "+Double.toString(angleA));
System.out.println("DELTA_A = "+Double.toString(deltaA));
System.out.println("AZIMUT_A = "+Double.toString(azimutA));
//System.out.println("Juergen_HAUTEUR = "+Double.toString(hoehe));
System.out.println("browseroffset = "+Double.toString(browserOffset));
System.out.println("locoffset = "+Integer.toString(locOffset));
System.out.println("Ma_DECLINAISON COS= "+Double.toString(Math.cos(array_declinaison[month])));
System.out.println("Ma_DECLINAISON SIN= "+Double.toString(Math.sin(array_declinaison[month])));
System.getProperty("user.region");
System.getProperty("user.timezone");
System.out.println("user.region = "+System.getProperty("user.region"));
System.out.println("user.timezone = "+System.getProperty("user.timezone"));
GeoLoc gl = new GeoLoc();
System.out.println("ma city= "+Double.toString(gl.LoadDataCity(System.getProperty("user.timezone"))));
}
public int conversionHMS(int h,int min, int sec){
//convertit l'heure en en secondes afin de pouvoir effectuer des operations dessus
int duree = 3600 * h + 60 * min + sec;
return duree;
}
//calcule coté
public double calc_cote (double longueur){
//Pythagore : A2+B2 C2 donc A racine(C/2)
double cote = Math.sqrt(longueur/2);
return cote;
}
//calcule une surface
public double calc_surface (double cote , double longueur){
double surface = cote*longueur;
return surface;
}
static class MyComponent extends JComponent {
MyComponent() {
System.out.println("in MYCOMPONENT()");
}
// This method is called whenever the contents needs to be painted
public void paint(Graphics g) {
System.out.println("in PAINT");
setBackground(Color.white);
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHints(renderHints);
//AJOUT
/*CIRCLES*/
/* g.setColor(Color.lightGray);
g.drawArc(centreFx-40, centreFy-40,80,80,0,360);
//g.setColor(Color.black);
g.setColor(Color.lightGray);
g.drawArc(centreFx-20, centreFy-20,40,40,0,360);
//g.setColor(Color.black);
g.setColor(Color.lightGray);
g.drawArc(centreFx-80, centreFy-80,160,160,0,360);
//g.setColor(Color.black);
g.setColor(Color.lightGray);
g.drawArc(centreFx-60, centreFy-60,120,120,0,360);
//g.setColor(Color.black);
*/
/*LIGNES*/
//resolution bug daffichage, si enleve alors ligne = noir
/* g.setColor(Color.lightGray);
//end resolution bug daffichage
//ligne horizontale vers la droite
g.drawLine(centreFx,centreFy,centreFx+180,centreFy);
g.setColor(Color.lightGray);
//ligne verticale vers le bas
g.drawLine(centreFx,centreFy,centreFx,centreFy+180);
g.setColor(Color.lightGray);
//ligne horizontale vers la gauche
g.drawLine(centreFx,centreFy,centreFx-180,centreFy);
g.setColor(Color.lightGray);
//ligne verticale vers le haut
g.drawLine(centreFx,centreFy,centreFx,centreFy-180);
g.setColor(Color.lightGray);
*/
//Maillage vertical: can be greater than 180!
for (int i=0; i<180; i=i+10){
for (int j=0; j<180; j=j+10){
g.setColor(Color.lightGray);
g.drawLine(centreFx+i,centreFy+180,centreFx+i,centreFy-180);
g.setColor(Color.lightGray);
g.drawLine(centreFx-i,centreFy+180,centreFx-i,centreFy-180);
}
}
//Maillage horizontal: can be greater than 180!
for (int i=0; i<180; i=i+10){
for (int j=0; j<180; j=j+10){
g.setColor(Color.lightGray);
g.drawLine(centreFx-180,centreFy+i,centreFx+180,centreFy+i);
g.setColor(Color.lightGray);
g.drawLine(centreFx-180,centreFy-i,centreFx+180,centreFy-i);
}
}
//CADRAGE VERTICAL
g.setColor(Color.lightGray);
g.drawLine(centreFx+180,centreFy+180,centreFx+180,centreFy-180);
g.setColor(Color.lightGray);
g.drawLine(centreFx-180,centreFy+180,centreFx-180,centreFy-180);
//CADRAGE HORIZONTAL
g.setColor(Color.lightGray);
g.drawLine(centreFx-180,centreFy+180,centreFx+180,centreFy+180);
g.setColor(Color.lightGray);
g.drawLine(centreFx-180,centreFy-180,centreFx+180,centreFy-180);
//AXE HORIZONTAL ROUGE
g.setColor(Color.red);
g.drawLine(centreFx-180,centreFy,centreFx+180,centreFy);
//AXE VERTICAL ROUGE
g.setColor(Color.red);
g.drawLine(centreFx,centreFy-180,centreFx,centreFy+180);
//CURSE OF THE SUN IS FROM EAST TO WEST, THRU SOUTH
//lets do it
//for(int i= centreFx+180; i<centreFx-180; i=i-20){
//for(int j= centreFy; i<centreFy+180; j=j+20){
for(int i= centreFx+180; i<centreFx; i=i-20){
for(int j= centreFy; i<centreFy+180; j=j+20){
g.setColor(Color.green);
g.drawOval(centreFx+i, centreFy+i, 20, 20);
}
}/*
g.setColor(Color.green);
g.fillOval(centreFx, centreFy+180, 20, 20);
*/
g.setColor(Color.green);
g.fillOval(centreFx+180, centreFy, 20, 20);
g.setColor(Color.green);
g.fillOval(centreFx+160, centreFy+20, 20, 20);
g.setColor(Color.green);
g.fillOval(centreFx+140, centreFy+40, 20, 20);
g.setColor(Color.green);
g.fillOval(centreFx, centreFy+180, 20, 20);
g.setColor(Color.green);
g.fillOval(centreFx-180, centreFy, 20, 20);
//end SunCurse
//POLYGON
g.setColor(Color.green);
switch(form){
case 0:;break;//square
case 1:;break;//rectangle
case 2:g.drawOval(centreFx-longueur/2, centreFy-longueur/2 ,longueur, longueur);break;//circle
case 3:;break;//polygon
}
g.setColor(Color.yellow);
if (mespoints.size() !=0){
//mespoints.toArray(array_point);
//COPY ARRAYLIST to ARRAY car manipulations impossibles sur Arraylist directement
array_point= (Point[]) mespoints.toArray(new Point[mespoints.size()]);
//mespoints.toArray(array_point);
if (array_point.length > 2){
//if (mespoints.size() > 2){
//if (mespoints.length > 2){
//il faut au moins trois points pour faire un polygone
Polygon p2 = new Polygon();
for (int i = 0; i0; i--){
for (int i=0; i0; i--){
//if (lspoly[i].contains(gotx, goty) == true){
if (array_polygon[i].contains(gotx, goty) == true){
System.out.println("we are in POLYGON ["+i+"]");
if (click == 2){
//double clicked
//array_polygon
//ArrayList lspoly= new ArrayList(Arrays.asList(array_polygon));
//on supprime le polygone actif
lspoly.remove(i);
//lspoly.remove(lspoly[i]);
//lspoly.toArray(array_polygon);
}else{
//si simple click: on redessine le polygon
}
}else{
System.out.println("we are OUTSIDE POLYGON["+i+"]");
//donc on dessine un polygone
//Point diff = new Point(e.getX(), e.getY());
//mespoints.add(diff);
//mespoints.add(e.getX());
//mespoints.add(e.getY());
mespoints.add(new Point(e.getX(), e.getY()));
}//end if
}
}
}//end mouseClicked
/*
private void putLine(int x1, int y1, int x2, int y2){
//Draw a line from (x1,y1) to (x2,y2) directly onto the applet
Graphics g = getGraphics();
g.drawLine(x1,y1,x2,y2);
g.dispose();
}*/
/*
private void putPolygon(){
//Draw a polygon described by th arrays xCoord and yCoord
//and the integer pointCt. A filled polygon with a black outilne is drawn. If pointCt is 0 or 1, nothing is drawn.
if (pointCt < 2){
return;
Graphics g = getGraphics();
}
if (pointCt == 2){
g.drawLine(xCoord[0], yCoord[0], xCoord[1], yCoord[1]);
}else{
g.setColor(Color.red);
g.fillPolygon(xCoord, yCoord, pointCt);
g.setColor(Color.black);
g.drawPolygon(xCoord, yCoord, pointCt);
}
g.dispose();
}*/
//public void mousePressed(MouseEvent e) {}
public void mousePressed(MouseEvent e){
/*
if(SwingUtilities.isRightMouseButton(e)) {
System.out.println("Right BTN !");
}else if(SwingUtilities.isLeftMouseButton(e)) {
System.out.println("Left BTN !");
}
*/
/*
if (e.isShiftDown()){
pointCt = 0;
repaint();
}else if (e.isMetaDown()||pointCt==500){
//draw the polygon and reset pointCt so that the user can start another polygon
putPolygon();
pointCt = 0;
}else{
//Add the point where the user clicked to the list of points
// in the polygon, and draw a line between the previois point and the current point
xCoord[pointCt] = e.getX();
yCoord[pointCt] = e.getY();
if (pointCt >= 2){
putLine(xCoord[pointCt-2], yCoord[pointCt-2],xCoord[pointCt-1], yCoord[pointCt-1]);
}
}
*/
mouseStart= e.getPoint();
int x = e.getX();
int y = e.getY();
xDragg = x - xPosition;
yDragg = y - yPosition;
moving = true;
}
public void mouseReleased(MouseEvent e) {
mouseStart = null;
if (moving){
xPosition = e.getX() - xDragg;
yPosition = e.getY() - yDragg;
moving = false;
repaint();
}
}
public void mouseDragged(MouseEvent e) {
if (mouseStart != null){
Point diff = new Point(e.getX()-mouseStart.x, e.getY()-mouseStart.y);
polygon.translate(diff.x, diff.y);
repaint();
}
mouseStart = e.getPoint();
if (moving){
xPosition = e.getX() - xDragg;
yPosition = e.getY() - yDragg;
repaint();
}
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
}//end MACLASSE
(_.:~:._)