Results 1 to 3 of 3
  1. #1
    gtraylo is offline Member
    Join Date
    Apr 2008
    Posts
    2
    Rep Power
    0

    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.
    Java 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); 
    			}

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    10

    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...
    Java 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)

  3. #3
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    9

    Default

    why not use ToolTextTip it does what ur trying to do, but a lot easier

Similar Threads

  1. Mouse dragg not working
    By Preethi in forum AWT / Swing
    Replies: 1
    Last Post: 02-08-2008, 05:51 AM
  2. The mouse and the cheese
    By Don Quixote in forum Java 2D
    Replies: 4
    Last Post: 08-15-2007, 10:55 PM
  3. mouse over on JButton
    By gradon in forum Java Applets
    Replies: 1
    Last Post: 08-04-2007, 05:50 AM
  4. Use the mouse position
    By susan in forum Java Applets
    Replies: 1
    Last Post: 07-28-2007, 11:10 PM
  5. Mouse over JButton
    By sandor in forum AWT / Swing
    Replies: 1
    Last Post: 05-17-2007, 09:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •