Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-20-2008, 05:56 AM
Member
 
Join Date: Apr 2008
Posts: 2
Rep Power: 0
gtraylo is on a distinguished road
Default Hovering mouse over a button and painting
The following code is what I have to try to paint a rectangle when ever I hover over a button. This rectangle will show a brief description of what the button will do. I'm doing something similar when pressing the help button and hovering over something a description in a rectangle shows up. But I cannot get the paint method to work. Can anyone tell me what I need to do to fix this.
Code:
public void mouseMoved(MouseEvent e) {
				//System.out.println("asdf");
				showMessage("Test");
			}
 
			private void showMessage(String string) 
			{ 
				public void paint(Graphics g) 
				{ 
					g.fillRect(25, 20, 20, 20);
					g.drawString("Hello", 25, 20); 
				} 
				//System.out.println(string); 
			}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 04-21-2008, 07:00 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 838
Rep Power: 4
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Default
What do you mean it will not work? Are you receiving errors? Is the rectangle not showing? Also, your code is a bit strange... this is the first time I've seen the paint method as you've shown... someone correct me if I'm wrong.. but I don't think you can have a method definition inside of another one...move the paint method outside of the showMessage method can we see the whole class and/or how you're using it...
Code:
public void mouseMoved(MouseEvent e) {
  //System.out.println("asdf");
  showMessage("Test");
}
            
private void showMessage(String string) { 
  //System.out.println(string);
}

public void paint(Graphics g) { 
  g.fillRect(25, 20, 20, 20);
  g.drawString("Hello", 25, 20); 
}
I realize this isn't the answer you're looking for but have a good read at the Sun tutorial on Mouse-Motion and other events.
__________________
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-24-2008, 10:33 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Rep Power: 2
Zosden is on a distinguished road
Default
why not use ToolTextTip it does what ur trying to do, but a lot easier
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mouse dragg not working Preethi AWT / Swing 1 02-08-2008 05:51 AM
The mouse and the cheese Don Quixote Java 2D 4 08-15-2007 11:55 PM
mouse over on JButton gradon Java Applets 1 08-04-2007 06:50 AM
Use the mouse position susan Java Applets 1 07-29-2007 12:10 AM
Mouse over JButton sandor AWT / Swing 1 05-17-2007 10:15 PM


All times are GMT +2. The time now is 08:42 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org