Results 1 to 4 of 4
- 01-22-2011, 11:50 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 3
- Rep Power
- 0
get the min X and min Y of an image drawn on the window
(in Java)using drawLine function i drew an image in black on (600,600) window.
now i wish to know the min value of X and Y co-ordinate of the image i drew and display it on the same window as soon i release my mouse button..
plzzz help me...m using net beans..Last edited by bizzareshishir; 01-22-2011 at 11:55 AM.
-
How are you doing the drawing to begin with? Are you creating and filling an ArrayList of Point objects and then iterating through this list in a JPanel's paintComponent method? Or are you drawing in a BufferedImage object that is displayed? Regardless, you get x and y points in the MouseListener, so keep track of them and save the lowest values.
- 01-22-2011, 12:32 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 3
- Rep Power
- 0
this is how i m drwaing...
.
.
Moderator edit: code tags addedJava Code:import java.awt.*; import java.awt.event.*; class anyshapekeborderpeovla extends Frame implements MouseListener,MouseMotionListener { BasicStroke b=new BasicStroke(4); int x,y,oldx,oldy; Color c=Color.BLACK; anyshapekeborderpeovla() { addMouseListener(this); addMouseMotionListener(this); setSize(600,600); setVisible(true); } public void mousePressed(MouseEvent e) { oldx= e.getX(); oldy= e.getY(); } public void mouseDragged(MouseEvent e) { int x= e.getX(); int y= e.getY(); Graphics g= getGraphics(); Graphics2D g2=(Graphics2D)g; g.setColor(c); g2.setStroke(b); g.drawLine(oldx,oldy,x,y); oldx= x; oldy= y; //System.out.println(oldx+":"+oldy); } public void mouseMoved(MouseEvent e) { } public void mouseClicked(MouseEvent e) {} public void mouseReleased(MouseEvent e) { } public void mouseExited(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public static void main(String arg[]) { new anyshapekeborderpeovla(); } }Last edited by Fubarable; 01-22-2011 at 01:00 PM. Reason: Moderator edit: code tags added
-
I don't know how to draw in AWT, so I can't advise you on the drawing itself, but as I noted above, you are getting your x and y values in your MouseListener:
Java Code:public void mouseDragged(MouseEvent e) { int x= e.getX(); int y= e.getY();
So it should be trivial to give the class two int values, minX and minY and check if the current x and y are lower than the current minX and minY respectively, and if so, reset the min values. I'm sure you've done this sort of program prior to doing GUI programming and here it's no different.
Also, I've added code tags to your post to help make the code more readable. To learn how to do this yourself, please read the link in my signature below.
Luck.
Similar Threads
-
How to clear Rectangle drawn using GC
By Tyler in forum SWT / JFaceReplies: 0Last Post: 06-24-2010, 10:51 AM -
piechart not being drawn on a panel
By dataprofiling in forum Java 2DReplies: 1Last Post: 03-27-2010, 11:33 AM -
[newbie] Rectangle2D not drawn within applet
By jon80 in forum New To JavaReplies: 7Last Post: 06-06-2009, 09:43 PM -
Canvas not being drawn
By tacosc in forum Java AppletsReplies: 4Last Post: 03-29-2009, 10:11 AM -
How do erase image drawn
By fernando in forum New To JavaReplies: 1Last Post: 08-06-2007, 05:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks