Results 1 to 6 of 6
- 10-24-2011, 04:23 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 38
- Rep Power
- 0
How can I click on an image from drawstring()?
I want to draw a string. Then I want the user to click on the JPanel and I want to take action depending upon whether or not the user clicked on the string.
Struggling to understand my textbook. From what I’ve read, I *think* I need a FontReaderContext and/or FontMetrics and/or LineMetrics.
My textbook isn't really giving me the sort of code examples I need.
Please can someone show me a bit of code along the lines I’m thinking?
Thanks.
- 10-24-2011, 04:56 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Re: How can I click on an image from drawstring()?
Don't draw the string. Use a JLabel, then you can just add a MouseListener to the label.
- 10-24-2011, 05:03 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 38
- Rep Power
- 0
Re: How can I click on an image from drawstring()?
Thanks. Yes, I thought of that, but I *think* drawString() might be better (or even necessary) - because I want my text to keep moving around like a moving target that the user has to hit (with a click). So I thought repaint() with a Timer would be the way to go.
Couldn't quite see how to do this with a JLabel: would I have to keep creating a "new JLabel("target")" with every repaint() and keep destructing the previous one from the previous repaint()?
- 10-24-2011, 05:21 PM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Re: How can I click on an image from drawstring()?
You can just use setLocation(...);
- 10-24-2011, 05:38 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 38
- Rep Power
- 0
Re: How can I click on an image from drawstring()?
Yes, of course. (I can be quite thick sometimes.)
Thanks.
- 10-24-2011, 08:00 PM #6
Member
- Join Date
- Oct 2011
- Posts
- 65
- Rep Power
- 0
Similar Threads
-
Executing .class files on Windows with a double click or right click
By Norm in forum Forum LobbyReplies: 2Last Post: 06-22-2011, 01:19 PM -
How to change size of drawString in Jpanel?
By david522 in forum New To JavaReplies: 1Last Post: 05-17-2011, 01:56 PM -
drawString() method not working correctly
By tnixon22 in forum New To JavaReplies: 2Last Post: 02-25-2011, 08:57 PM -
help with drawString
By h3nch in forum AWT / SwingReplies: 5Last Post: 01-16-2010, 02:58 PM -
drawString with Chinese Characters
By vaskarbasak in forum Advanced JavaReplies: 1Last Post: 06-10-2008, 07:49 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks