Hi all,
I want to draw a rectangle by dragging mouse. I am getting co-ordinates of starting point and endpoint but rectangle is not drawn.
Please help me about this.
Thanks in advance...
Printable View
Hi all,
I want to draw a rectangle by dragging mouse. I am getting co-ordinates of starting point and endpoint but rectangle is not drawn.
Please help me about this.
Thanks in advance...
Post the code. How are we supposed to tell you what to change, without seeing the code?
Hi PhHein,
I modified my code. now rectangle is getting drawn by dragging mouse but it not showing path where we are drawing(like in paint , when we draw a rectangle it shows all its corners)
Here is a code,
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,endDrag.y,e.x,e.y,displa y);
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);
//shell.redraw();
}
public void mouseUp(MouseEvent e){
makeRectangle(startDrag.x,startDrag.y,e.x,e.y,disp lay);
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();
}
});
}
Please explain again. I don't understand what "path" is here?Quote:
not showing path
Cross-posted in the JavaRanch swt forum. Please read what JavaRanch has to say about cross-posting in their FAQ's.
path means all the sides of rectangle..
During dragging mouse it is not showing rectangle which is being drawn....
You tried debugging the code by adding println() to show where the control is going and what the values are that you used to draw with.
What do you see when you execute the code? Where is the program executing and what are the values?
Values which I am getting are correct. Problem is GC is not drawing rectangle according to that values.
Can you post the debug output that shows what's happening?
Where is GC define? Without seeing the code, its very hard to help.Quote:
GC is not drawing rectangle
Can you make a small executable program that demos the problem?
Spammer linzh6688 reported.
db