Drag n Drop проблэм трабл!

 
 
 
Сообщения:81
vps, thanks for you!!!

Yn=Xn {n: 1, 2, ... 54}
 
 
Сообщения:81
Немного доработал: есть возможность слушать keyboard!!! Тему можно =закрыта!!!
//Вот последняя версия уголков без AI - for two players only!!!
package j;
 //Author: Alunts Arthur Arthurovich;
//tel: +79923502525;
//facebook: https://www.facebook.com/counter.vector
import java.awt.AWTException;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Robot;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Ellipse2D;
import java.util.regex.Pattern;
import javax.swing.JFrame;
import javax.swing.JPanel;
 
 
 
 
 
 
 
 public class J20 extends JPanel implements MouseMotionListener {
  
/**
 * @author Arthur Alunts Arthurovich
 * @tel : +79923502525
*/
  public static int D2=50;
  public static int iii_ii=1;
  public static int GM=17; //default est from 1 to 0
  public static String GS="!!!!!!!!!!!!!!!!"; // default are 0 or from 1 to 10;
  public static int R1=725,R2=725;
  public static JFrame jf=new JFrame();                                                    
  public static int n=45;
  public static String de="_";
  public static double q=64.0;
  public static double p=Math.PI/q;
  public static double R=44;
  public static int y=1;
  public static int x=1;
  public static double r=12;
  public static double h=11;
  public static Point lastCursorPoint;
  public static int C=100;
  public static double t[];
  public static int CY=0;
  public static int CX=0;
  public static double x2[]=new double[110+1];
  public static double y2[]=new double[110+1];
  public static double CellSize=50.0;
  public static double[]XT=new double[110+1];
  public static double[]YT=new double[110+1];
  public static double FigureSize=50.0;
  public static double Delay =(CellSize-FigureSize)/2.0;
  public static int alt=1;
  public static double[]Ycu;
  public static double[]Xcu;       
  public static String[][] G=new String[12+1][12+1];
  public static int[][] M =new int[12+1][12+1];
  public static String []F =new String[18+1];
  public static String[] Moved=new String[200];  
  public static int E[][]=new int[9][9];
  
//public static String []A_Table =new String[1+18]; 
  
  public static String TS[];
  public static int TI[];
  
  public static int a=0;
  public static int b=0;
  public static int c=0;
  public static int d=0;
  
  public static int CallUmora=2;
  public static int all=0;
  
  
  public static String[] Move=new String[1000];
  
  
     public static   int GY=1, GX=1;
        private static final int D1 = 10;
     private static final int releve = (int)CellSize;
    private static final int MAX = 18;
    private static Ellipse2D.Double[] CD = new Ellipse2D.Double[MAX];
    private static int N = 0;
    public static int currentSquareIndex = -1;
 public static void G(){//Заполним координаты G[y][x]=gy_gx
   Xcu= new double[100+1];
   Ycu= new double[100+1];   
   
       int ii=0;
   for(int y=1; y<=8;y=y+1){
   for(int x=1; x<=8;x=x+1){
   G[y][x]="0_0";
   //T[y][x]=0;
   }
   }
   
   C=0;
   for(int y=1; y<=9;y=y+1){
   for(int x=1; x<=9;x=x+1){
    ii++;
    x2[ii]=x*CellSize-D2;
    y2[ii]=y*CellSize-D2;
    G[y][x]=(int)((y*CellSize)-D2)+de+(int)(x*CellSize-D2);
   // for(int z=1;z<=8;z++){
        // for(int m =1;m<=8; m++){
            // System.out.println(G[z][m]+"y: " + z + "x: " + m );}
                      //   }
            
       //Xp[ii]=C+x*CellSize+CellSize/2.0;
       //Yp[ii]=C+y*CellSize+CellSize/2.0;
       
      // System.out.println("Stringer "+ G[y][x]  );
      
   
   }}
   
   
   //Запоним M[]
   for(int y=1; y<=8;y=y+1){
   for(int x=1; x<=8;x=x+1){
   M[y][x]=0;
   //T[y][x]=0;
   
   }
   }
   
     
   
   
  M[1][1]=1;F[1]=1+de+1+de+G[1][1];
  M[1][2]=2;F[2]=1+de+2+de+G[1][2];
  M[1][3]=3;F[3]=1+de+3+de+G[1][3];
  M[2][1]=4;F[4]=2+de+1+de+G[2][1];
  M[2][2]=5;F[5]=2+de+2+de+G[2][2];
  M[2][3]=6;F[6]=2+de+3+de+G[2][3];
  M[3][1]=7;F[7]=3+de+1+de+G[3][1];
  M[3][2]=8;F[8]=3+de+2+de+G[3][2];
  M[3][4]=9;F[9]=3+de+3+de+G[3][3];
  M[6][6]=10;F[10]=6+de+6+de+G[6][6];
  M[6][7]=11;F[11]=6+de+7+de+G[6][7];
  M[6][8]=12;F[12]=6+de+8+de+G[6][8];
  M[7][6]=13;F[13]=7+de+6+de+G[7][6];
  M[7][7]=14;F[14]=7+de+7+de+G[7][7];
  M[7][8]=15;F[15]=7+de+8+de+G[7][8];
  M[8][6]=16;F[16]=8+de+6+de+G[8][6];
  M[8][7]=17;F[17]=8+de+7+de+G[8][7];
  M[8][8]=18;F[18]=8+de+8+de+G[8][8];
    
   /*  
  M[1][6]=3;F[3]=1+de+6+de+G[1][6];
  M[1][7]=2;F[2]=1+de+7+de+G[1][7];
  M[1][8]=1;F[1]=1+de+8+de+G[1][8];
  M[2][6]=6;F[6]=2+de+6+de+G[2][6];
  M[2][7]=5;F[5]=2+de+7+de+G[2][7];
  M[2][8]=4;F[4]=2+de+8+de+G[2][8];
  M[3][6]=9;F[9]=3+de+6+de+G[3][6];
  M[3][7]=8;F[8]=3+de+7+de+G[3][7];
  M[3][8]=7;F[7]=3+de+8+de+G[3][8];
  M[6][1]=16;F[16]=6+de+1+de+G[6][1];
  M[7][1]=17;F[17]=7+de+1+de+G[7][1];
  M[8][1]=18;F[18]=8+de+1+de+G[8][1];
  M[6][2]=13;F[13]=6+de+2+de+G[6][2];
  M[7][2]=14;F[14]=7+de+2+de+G[7][2];
  M[8][2]=15;F[15]=8+de+2+de+G[8][2];
  M[6][3]=10;F[10]=6+de+3+de+G[6][3];
  M[7][3]=11;F[11]=7+de+3+de+G[7][3];
  M[8][3]=12;F[12]=8+de+3+de+G[8][3];
   */
   }
 
 
 public static int ladan(int iii ){
   int crion=iii;
     for(int ii = 1;ii<=8;ii++){
      for(int i = 1;i<=8;i++){
         if(M[ii][i]!=0){
           if((M[ii][i])==iii){
              GS = G[ii][i];
                GM = M[ii][i];
                  crion=iii;
                    
               
        } 
         
 
 }
 }
 
 
 }
 
 return crion;
 
 }
 
 public static void ladan12(int G1 ,int G2 ){
 
    for(int ii = 1;ii<=8;ii++){
      for(int i = 1;i<=8;i++){
         String[] tg=G[ii][i].split(de);
           GY=Integer.valueOf(tg[0]);
            GX=Integer.valueOf(tg[1]);
              if(GY==ii && GX==i ) {
                System.out.println(GY+"_"+ ii+"____"+ GX +"_"+ i);
                  
              
              
              }      
      }}}  
 
 
 
 
 
  public static int YARD1 = 1, YARD2 = 1;
  public static int Y1 = 1, X1= 1,Y2=1,X2=1;
    public static void public44(int G2, int G1) {
      
        for (int y = 1; y <= 8; y++) {
            for (int x = 1; x <= 8; x++) {
                String[] th = null;
                th = G[y][x].split(de);
                YARD1 = Integer.valueOf(th[1]);
                YARD2 = Integer.valueOf(th[0]);
                if (YARD2 == G2 && YARD1 == G1) {
                    Y1 = y;
                    X1 = x;
                    //System.out.println("YARD2: " + YARD2 +"y: " + G2 + "  YARD1:  " + YARD1 +" x: "+ G1);
                  //  System.out.println("y: " + MyY + "    x: " + MyX);

                }
                //  }
            }
        }

    }
public static void public45(int G2, int G1) {

        for (int y = 1; y <= 8; y++) {
            for (int x = 1; x <= 8; x++) {
                String[] th = null;
                th = G[y][x].split(de);
                YARD1 = Integer.valueOf(th[1]);
                YARD2 = Integer.valueOf(th[0]);
                if ( G2>=YARD2 && G1>=YARD1 && G2<YARD2+CellSize && G1<YARD1+CellSize) {
                   
                   Y2 = y;
                   X2 = x;
                    //System.out.println("YARD2: " + YARD2 +"y: " + G2 + "  YARD1:  " + YARD1 +" x: "+ G1);
                  //  System.out.println ("______"+"Y2: " + Y2 + "  Y2:" + X2);

                }
                //  }
            }
        }

    }
public static void M(){
   
 
    currentSquareIndex = getRec(x, y);
 
    //if (currentSquareIndex < 0) // not inside a square
 
    {   
      TS=null;
       TI=null;
        TI=new int[4];
         
    for(int i=1; i<=18;i=i+1){
        
         f++;
                   
          TS=F[f].split(Pattern.quote(de));
            TI[0]=Integer.valueOf(TS[0]);
              TI[1]=Integer.valueOf(TS[1]);
                TI[2]=Integer.valueOf(TS[2]);
                  TI[3]=Integer.valueOf(TS[3]);
                    
            a=TI[0];
            b=TI[1];
            c=TI[2];
            d=TI[3];
            
            
                             
             
            
//System.out.println(a+" PP "+MyY +" PP "+ b+" PP "+MyX);
            
            
              int F=f;
             add(c, d);
 
    }}
            public45(y,x);
            
            
           System.out.println(" Y2: " + Y2+ "  X2: "+ X2);
           f=0;    
}
  public static String hod="";
  public static int f=0;
    public J20() {
 
 addMouseListener(new MouseAdapter() {
 
      
 @Override
 public void mousePressed(MouseEvent evt) {
    int x = evt.getX();
    int y = evt.getY();
    M();
 }
 /*
@Override
 
public void mouseClicked(MouseEvent evt) {
 
    int x = evt.getX();
 
    int y = evt.getY();
 
    if (evt.getClickCount() >= 2) {
 
  remove(currentSquareIndex);
 
    }
 
}*/
 @Override
        public void mouseReleased(MouseEvent evt) {
        int xx = evt.getX();
        int yy = evt.getY();
     int f=0;   
      TS=null;
       TI=null;
        TI=new int[2];
         
    for(int y=1;y<=8;y++){
      for(int x=1;x<=8;x++){
       
          f++;
            
           TS=G[y][x].split(Pattern.quote(de));
            TI[0]=Integer.valueOf(TS[0]);
              TI[1]=Integer.valueOf(TS[1]);
          
            c=TI[0];
            d=TI[1];
            if(yy<=c+CellSize && xx<=d+CellSize && yy>c && xx>d){
            
        
       
            if(currentSquareIndex>-1){
                
            CD[currentSquareIndex].y = c;
            CD[currentSquareIndex].x = d;
            
            
            
            
            for(int i=0;i<=17;i++){
            
           
           // CD[CallUmora].y = 270;//havay hoder po prikolu (haykakan)
           // CD[CallUmora].x = 270;    
            
            
            
            }
            
            public44(c,d); 
            System.out.println("Y1: " + Y1+ "  X1: "+ X1);
            add (c,d); 
            }}}}}
   
            
            
            
            
           
       
      
 
 
  });
 
  addMouseMotionListener(this);
    }
 
 
    @Override
protected void paintComponent(Graphics g)
  {
    try {
           
        super.paintComponent(g);
         
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                        RenderingHints.VALUE_ANTIALIAS_ON);
  
       
            
            
            Graphics2D g2d = (Graphics2D) g;
           
           g2d.setStroke(new BasicStroke(1.1f));  // толщина равна 10
            
            
            /*
            g2d.setRenderingHint(
                    RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            */
// You can also enable antialiasing for text:
 
//g2d.setRenderingHint(
   //     RenderingHints.KEY_TEXT_ANTIALIASING,
    //    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
//write either "RED" or "BLUE" using g
g.setColor(Color.LIGHT_GRAY);
//g.drawRect(0, 0, 100, 100);
 
g.setFont(new Font("serif", Font.BOLD, 60));
 
Color c1 = new Color(240, 240, 245);//желтый
Color c2 = new Color(232, 134, 36);    //рыжий
Color c3 = new Color(255, 255, 255);      //белый
Color c4 = new Color(0, 0, 0);      //черный
Color c5 = new Color(2, 193, 88); //берюзовый
 
Color c6 = new Color(253, 179, 53);// Orange 2   
 
     
      

g.setColor(Color.BLACK);
for(int i=1;i<=81;i++){
    
   g2d.drawRect((int)x2[i],(int)y2[i],(int)CellSize,(int)CellSize);
   
   
}
 
 
 
 
g.setColor(c1);
 
for(int k= 1;k<=81;k=k+1){
g2d.fillRect((int)x2[k],(int)y2[k],(int)CellSize,(int)CellSize);
 
 
}
 
g.setColor(c4);
 
for(int k= 2;k<=81;k=k+2){
g2d.fillRect((int)x2[k],(int)y2[k],(int)CellSize,(int)CellSize);
 
 
}
 
 
 
 
g.setColor(c1);
for(int i=72;i<=81;i++){
    
   g2d.fillRect(734,120,(int)CellSize,9*(int)CellSize);
   
   
}
g.setColor(c1);
for(int i=72;i<=81;i++){
    
   g2d.fillRect(120,734,9*(int)CellSize,+(int)CellSize);
   
  
}
 
 //g.setColor(c4);
 
   
 
 //g.setColor(Color.RED);
//for(int i=1;i<=9;i=i+1){
 
//g2d.fillOval((int)J.Xcu[i]+(int)(J.Delay), (int)J.Ycu[i]+(int)(J.Delay), (int)J.FigureSize,(int)J.FigureSize);
 
//}
//йоднвая клетка
g.setColor(Color.BLACK);
for(int i=1;i<=81;i++){
    
   g2d.drawRect((int)x2[i],(int)y2[i],(int)CellSize,(int)CellSize);
   
   
}
 
//Rangering figures blue///////////////////////////////////////////////////////
 //Rangering figures blue///////////////////////////////////////////////////////
 //g.setColor(c5);
 
 
 //System.out.println(aa+de+bb);
//if(f>9){g.setColor(c6);}
 
            //System.out.println("a b c d :"+ a+"_"+ b+"_"+ c+"_" +d  );
           //System.out.println(Arrays.asList(TS));
          
        // g2d.fillOval(c,d, (int)FigureSize,(int)FigureSize);
  
 

    
    
    
    
    //repaint();
 
Thread.sleep(0);
  
   
           
  
 
 
 
  for (int i = 0; i < N; i++) {
  if( i>=0 && i<=8){g.setColor(new Color(111,168,200,128));}
 else if(i>=9 && i<=17){g.setColor(new Color(100,200,110,128));}
((Graphics2D) g).fill(CD[i]);
   g.setColor(Color.WHITE);
((Graphics2D) g).draw(CD[i]);}
 
  g.setColor(Color.BLUE);
  String s = x + ", " + y;

 g.drawString(s,400, 300);
 
 //g.drawString(J1.SSS,200, 200);
  repaint();
  
    
    }catch (InterruptedException ex) {ex.printStackTrace();}}
    
 
public static int getRec(int x, int y) {
 
  for (int i = 0; i < N; i++) {
 
if (CD[i].contains(x, y)) {
 
    return i;
 
}
 
  }
 
  return -1;
    }
 
    public static void add(int x, int y) {
 
  if (N < 18) {
   
        
 
CD[N] = new Ellipse2D.Double(x, y, releve, releve);
 
currentSquareIndex = N;
 
N++;
 //repaint();
  }
    }
 
    @Override
    public void remove(int n) {
 
  if (n < 0 || n >= N) {
 
return;
 
  }
 
  N--;
 
  CD[n] = CD[N];
 
  if (currentSquareIndex == n) {
 
currentSquareIndex = -1;
 
  }
 
  repaint();
    }
 
    @Override
    public void mouseMoved(MouseEvent event) {
 
  x = event.getX();
 
  y = event.getY();
 
  if (getRec(x, y) >= 0) {
 
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
 
  } else {
 
setCursor(Cursor.getDefaultCursor());
 
  }
  
  
 // lastCursorPoint = event.getPoint();
  //System.out.println("q:" + lastCursorPoint.x + " q: " + lastCursorPoint.y);
 // x=lastCursorPoint.x;
 // y=lastCursorPoint.y;      
  repaint();
  
  
  
    }
   
       
    
    
    @Override
    public void mouseDragged(MouseEvent event) {
 
  x = event.getX();
 
  y = event.getY();
 
  if (currentSquareIndex >= 0) {
 
Graphics g = getGraphics();
 
///g.setXORMode(getBackground());
 
 
CD[currentSquareIndex].x = x-CellSize/2;
 
CD[currentSquareIndex].y = y-CellSize/2;
 
//((Graphics2D) g).fill(CD[currentSquareIndex]);
 
//g.dispose();
 //repaint();
  }
    }
   
        
     
    
    
 public static void click(int x , int y,int x2, int y2) throws AWTException, InterruptedException{
    Robot b11 = new Robot();
    
    b11.mouseMove(x, y);    
    b11.mousePress(InputEvent.BUTTON1_DOWN_MASK);
    Thread.sleep(777);//Здесь можно преминить уравнение прямой проходящее через 2 точки!!!
    b11.mouseMove(x2, y2);
    b11.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
    b11.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
 
    public static void main(String[] args) throws AWTException, InterruptedException {
   G();
 
  
  JFrame jFrame = new JFrame();
  
  jFrame.setTitle("MailMacintosh");
 
  jFrame.setSize(R1, R2);
 
  jFrame.addWindowListener(new WindowAdapter() {
 
      
      

 @Override
public void windowClosing(WindowEvent e) {
 
    System.exit(0);
 
}
 
  });
 
  Container cPane = jFrame.getContentPane();
  
  cPane.add(new J20());
  jFrame.addKeyListener(new J1(jFrame));
  jFrame.setVisible(true);
   int k=0;
   // x=25;y=25;
      
    M();
    //if(z!=1){
    
    
   // }
    //M();
    //Thread.sleep(1000);
    //Первый ход для инициаизации обхода бага 0x00010.0 
    //click(260+25, 260+25, 86,86);
   // click(384, 503, 384,555);
   // Thread.sleep(100);
    
    //click(384, 503, 384,555);
    //click(202, 202, 77+25,77+25);
   // Thread.sleep(100);
    int UX=8;  int UY=30; int D=25;
   // click(174+U,174+U,200,260+U);
  //  Thread.sleep(100);
    //click(0,0,0,0);
    //Thread.sleep(3000);
    //click(100+D+UX,100+UY+D,100+UX+D,150+UY+D);
    //Thread.sleep(3000);
    
    
    //click((int)x2[3]+UX+D,(int)y2[1]+UY+D,100+UX+D,200+UY+D);
    
    

    
   //for(int y=1;y<=8;y++){
    //for(int x=1;x<=8;x++){
        //System.out.println(G[1][1]);
        
        //}}

    }
public static void maple () {
     
//if(MY==G1 && MX=G2)
 ///String TK1=null;
 ///int TG=G[G2][G1]split(de);
 //TG
        
//int TH split()
 
 }

}


class J1 implements KeyListener {
    
    JFrame frame;
    
    
    public J1(JFrame j) {
        frame = j;
    }
public static String SSS="";
    
    public void keyPressed(KeyEvent e) {
       

        /* We add some text that actually shows the keyCode (left arrow = 37, top = 38, right = 39, bottom = 40) */
       SSS=String.valueOf(e.getKeyCode());
       //if(String.valueOf(e.getKeyCode()).equals("37")){System.out.println("OK_37_Key_Valued");}//Yturieowpq
       System.out.println("Key Pressed: "+e.getKeyCode() +" ");
        /* Redrawing the window */
        frame.revalidate();
    }

    /* These two are part of the contract we made when we decided to
     * implement the KeyListener */
    public void keyTyped(KeyEvent e) { /* Do nothing */ }
    public void keyReleased(KeyEvent e) { /* Do nothing */ }
}

Yn=Xn {n: 1, 2, ... 54}
Изменен:13 фев 2019 19:59
 
Модераторы:Нет
Сейчас эту тему просматривают:Нет