Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Dheeraj Kasar
Greenhorn
+ Follow
2
Posts
1
Threads
0
Cows
since Jul 14, 2010
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
Ranch Hand Scavenger Hunt
Number Posts (2/100)
Number Threads Started (1/100)
Number Cows Received (0/5)
Number Likes Received (0/10)
Number Likes Granted (0/20)
Set bumper stickers in profile (0/3)
Report a post to the moderators (0/1)
Edit a wiki page (0/1)
Create a post with an image (0/2)
Greenhorn Scavenger Hunt
First Post
Number Posts (2/10)
Number Threads Started (1/10)
Number Likes Received (0/3)
Number Likes Granted (0/3)
Set bumper stickers in profile (0/1)
Set signature in profile
Search for a post/thread (0/3)
Set a watch on a thread
Save thread as a bookmark
Create a post with an image (0/1)
Recent posts by Dheeraj Kasar
Draw rectangle by dragging mouse
Here..I am posting my code...I have modified it. It is now displaying rectangle but during dragging mouse it is showing all mouse moves.
public void makeRectangle(int x1, int y1, int x2, int y2,Display display) { // TODO Auto-generated method stub GC gc = new GC(display); gc.drawRectangle(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(y1 - y2)); gc.dispose(); } public void run(IAction action) { // TODO Auto-generated method stub final Display display = PlatformUI.getWorkbench().getDisplay(); final Shell shell = display.getActiveShell(); Cursor crossCursor = display.getSystemCursor(SWT.CURSOR_CROSS); shell.setCursor(crossCursor); shell.addPaintListener(new PaintListener(){ public void paintControl(PaintEvent e) { // TODO Auto-generated method stub if (startDrag != null && endDrag != null){ makeRectangle(startDrag.x,startDrag.y,endDrag.x,endDrag.y,display); System.out.println("In paintlistener StartDrag:"+startDrag+" "+"end drag:"+endDrag); } } }); shell.addMouseListener(new MouseAdapter(){ public void mouseDown(MouseEvent e){ startDrag = new Point(e.x, e.y); endDrag = startDrag; System.out.println("In mouse Down StartDrag:"+startDrag+" "+"end drag:"+endDrag); } public void mouseUp(MouseEvent e){ makeRectangle(startDrag.x,startDrag.y,e.x,e.y,display); System.out.println("In mouse Up StartDrag:"+startDrag+" "+"end drag:"+endDrag); System.out.println(e.x+" "+e.y); startDrag = null; endDrag = null; // shell.redraw(); } }); shell.addMouseMoveListener(new MouseMoveListener(){ public void mouseMove(MouseEvent me){ endDrag = new Point(me.x,me.y); System.out.println("In mouse move StartDrag:"+startDrag+" "+"end drag:"+endDrag); shell.redraw(); } }); }
show more
13 years ago
Swing / AWT / SWT
Draw rectangle by dragging mouse
Hi all,
I want to draw a rectangle by dragging mouse using SWT. I am getting co-ordinates of starting point and endpoint but rectangle is not drawn.
Please help me about this.
Thanks in advance...
show more
13 years ago
Swing / AWT / SWT