computor Posted January 29, 2015 Share Posted January 29, 2015 public void mousePressed(MouseEvent e) { Point clicked; clicked = e.getPoint(); Rectangle paintArea = new Rectangle((int)startX, (int)startY, mainPaint.getWidth(null), mainPaint.getHeight(null)); //xPos,yPos,width,height if(paintArea.contains(clicked)){ startX = clicked.getX(); startY = clicked.getY(); } } This doesn't seem to work. startX and startY are double values. Why doesn't it work? Link to comment Share on other sites More sharing options...
Isolate Posted January 29, 2015 Share Posted January 29, 2015 (edited) public void mousePressed(MouseEvent e) { Point clicked; clicked = e.getPoint(); Rectangle paintArea = new Rectangle((int)startX, (int)startY, mainPaint.getWidth(null), mainPaint.getHeight(null)); //xPos,yPos,width,height if(paintArea.contains(clicked)){ startX = clicked.getX(); startY = clicked.getY(); } } This doesn't seem to work. startX and startY are double values. Why doesn't it work? What is this supposed to do sorry EDIT: EDIT EDIT: fixed some things You mean something like this?: boolean dragging = false; Rectangle paintArea; @Override public void onPaint(Graphics2D g) { int x = 0; //set to where you want it to start off int y = 0; //set to where you want it to start off if(dragging){ x = mouse.getPosition().x; y = mouse.getPosition().y; } paintArea = new Rectangle(x, y, mainPaint.getWidth(null), mainPaint.getHeight(null)); } @Override public void mousePressed(MouseEvent e) { if(painArea != null){ if(paintArea.contains(e.getPoint()){ dragging = true; } } } @Override public void mouseReleased(MouseEvent e) { if(painArea != null && dragging){ dragging = true; } } Edited January 29, 2015 by Isolate Link to comment Share on other sites More sharing options...
computor Posted January 29, 2015 Author Share Posted January 29, 2015 What is this supposed to do sorry EDIT: EDIT EDIT: fixed some things You mean something like this?: boolean dragging = false; Rectangle paintArea; @Override public void onPaint(Graphics2D g) { int x = 0; //set to where you want it to start off int y = 0; //set to where you want it to start off if(dragging){ x = mouse.getPosition().x; y = mouse.getPosition().y; } paintArea = new Rectangle(x, y, mainPaint.getWidth(null), mainPaint.getHeight(null)); } @Override public void mousePressed(MouseEvent e) { if(painArea != null){ if(paintArea.contains(e.getPoint()){ dragging = true; } } } @Override public void mouseReleased(MouseEvent e) { if(painArea != null && dragging){ dragging = true; } } I'm trying to get the paint to move. That too does not work. Link to comment Share on other sites More sharing options...
Isolate Posted January 29, 2015 Share Posted January 29, 2015 (edited) I'm trying to get the paint to move. That too does not work. click and drag? or just click and assumed magic? Is this test also including my double edit or only the first edit hmmmm hb: boolean dragging = false; Rectangle paintArea = null; @Override public void onPaint(Graphics2D g) { if(paintArea == null){ paintArea = new Rectangle(x, y, mainPaint.getWidth(null), mainPaint.getHeight(null)); }else{ if(dragging){ paintArea.x = mouse.getPosition().x; paintArea.y = mouse.getPosition().y; } } } @Override public void mousePressed(MouseEvent e) { if(painArea != null){ if(paintArea.contains(e.getPoint()){ dragging = true; } } } @Override public void mouseReleased(MouseEvent e) { if(dragging){ dragging = false; } } Code is starting to look overcomplicated though Edited January 29, 2015 by Isolate Link to comment Share on other sites More sharing options...
computor Posted January 29, 2015 Author Share Posted January 29, 2015 click and drag? or just click and assumed magic? Is this test also including my double edit or only the first edit hmmmm hb: boolean dragging = false; Rectangle paintArea = null; @Override public void onPaint(Graphics2D g) { if(paintArea == null){ paintArea = new Rectangle(x, y, mainPaint.getWidth(null), mainPaint.getHeight(null)); }else{ if(dragging){ paintArea.x = mouse.getPosition().x; paintArea.y = mouse.getPosition().y; } } } @Override public void mousePressed(MouseEvent e) { if(painArea != null){ if(paintArea.contains(e.getPoint()){ dragging = true; } } } @Override public void mouseReleased(MouseEvent e) { if(dragging){ dragging = false; } } Code is starting to look overcomplicated though Still no, I guess I'll just request a tutorial on getting paint to move on mouseDrag Link to comment Share on other sites More sharing options...
Extreme Scripts Posted January 29, 2015 Share Posted January 29, 2015 Is "mainPaint" even a object? In order to pull of something like this you will need to make a rectangle, then wherever you click on the rectangle get that (x,y) value and wherever your mouse ends up calculate the new (x,y) value. Then you also have to calculate the corresponding (x,y) values for the strings you are painting (relative positioning seems best for this). I dunno what those two methods above were about Link to comment Share on other sites More sharing options...
computor Posted January 30, 2015 Author Share Posted January 30, 2015 Is "mainPaint" even a object? In order to pull of something like this you will need to make a rectangle, then wherever you click on the rectangle get that (x,y) value and wherever your mouse ends up calculate the new (x,y) value. Then you also have to calculate the corresponding (x,y) values for the strings you are painting (relative positioning seems best for this). I dunno what those two methods above were about Mainpaint is just the Image of the paint. I tried doing something like this, got the the paint to move to where i clicked the mouse, but I couldn't click and drag it, Also, I was only able to click inside the paint, which only made the paint move to the bottom right hand corner of the screen. Tried getting it to be able to follow mouse, but I can't. Any ideas? Link to comment Share on other sites More sharing options...
Mysteryy Posted January 30, 2015 Share Posted January 30, 2015 public void mousePressed(MouseEvent e) { Point clicked; clicked = e.getPoint(); Rectangle paintArea = new Rectangle((int)startX, (int)startY, mainPaint.getWidth(null), mainPaint.getHeight(null)); //xPos,yPos,width,height if(paintArea.contains(clicked)){ startX = clicked.getX(); startY = clicked.getY(); } } This doesn't seem to work. startX and startY are double values. Why doesn't it work? Ill hint what you need to do, you will have to put in the effort of coding it. -When the mouse is clicked, check if the mouse is in the paint area. -If the mouse is in the paint area, update the x, y values of the paint to the mouse x, y coordinates (in the onPaint method, use variables for this). This will move the paint around to the mouse position while the mouse is being held down. -when the mouse is released, stop moving the paint. You should think of a logical way to do it before just trying to code it. Link to comment Share on other sites More sharing options...
Isolate Posted January 30, 2015 Share Posted January 30, 2015 Ill hint what you need to do, you will have to put in the effort of coding it. -When the mouse is clicked, check if the mouse is in the paint area. -If the mouse is in the paint area, update the x, y values of the paint to the mouse x, y coordinates (in the onPaint method, use variables for this). This will move the paint around to the mouse position while the mouse is being held down. -when the mouse is released, stop moving the paint. You should think of a logical way to do it before just trying to code it. I swear thats what i gave a snippet of (although it was 1am and i might have missed something) Link to comment Share on other sites More sharing options...
Mysteryy Posted January 30, 2015 Share Posted January 30, 2015 I swear thats what i gave a snippet of (although it was 1am and i might have missed something) What you posted wont even paint anything. It looks like you had the right idea, but the syntax wasnt there. Link to comment Share on other sites More sharing options...