Solved

MouseOver

Posted on 1998-05-13
16
329 Views
Last Modified: 2010-04-16
I am trying to write an applet button that when the mouse scrolls over it it will give a bubble help type windows
help description sort of like the ALT tags function describing the buttons description and when the mouse is not over the windows help type screen goes away. And also trying to make button a link when actually clicked
on
0
Comment
Question by:jbird090897
  • 6
  • 6
  • 2
  • +2
16 Comments
 

Expert Comment

by:thorner
ID: 1220977
Create a bubble image and the in mouseover load the image.
0
 

Author Comment

by:jbird090897
ID: 1220978
scratch the bubble image,i am trying to make a standard button that when the mouse moves over it, it gives a description of that button,its sort of like on a windows95 system
if you pass the mouse over one of the icons it gives a small yellow help box
0
 
LVL 2

Expert Comment

by:aziz061097
ID: 1220979
This is a property in Swing TextFields .
0
 

Expert Comment

by:thorner
ID: 1220980
Use a separate method to draw a box and insert text into that box.  When the mouse goes over the button load that method.  That's the easiest way I can think of.  As far as the link part, try this:

import java.net.*;

public class URL extends Applet implements ActionListener
{    
     private Button link;

     public void init()
     {
          URL url;

          url = new URL("http://yourURL.com");
     
          link = new Button("Click Here...");
          add(link);
          link.addActionListener(this);
     }

     public void actionPerformed(ActionEvent e)
     {
          if(e.getSource() == link)
               getAppletContext().showDocument(url);
     }
}

Add the rest of the code for the button to this. It should work.
0
 

Author Comment

by:jbird090897
ID: 1220981
How do i use another method to draw the box and add text to ,
i am alittle bit of a beginner and dont know how toi just tried to compile the java code
and it had errors undefined name  Applet. I named the applet  URL maybe that
could be the problem.
0
 

Expert Comment

by:thorner
ID: 1220982
Okay, I forgot some things.  Try this:

      import java.applet.Applet;
      import java.awt.*;
      import java.awt.Event.*;
      import java.net.*;

      public class URL extends Applet implements ActionListener
      {      
           private Button link;

           public void init()
           {
                URL url;

                url = new URL("http://yourURL.com");
           
                link = new Button("Click Here...");
                add(link);
                link.addActionListener(this);
           }

           public void actionPerformed(ActionEvent e)
           {
                if(e.getSource() == link)
                     getAppletContext().showDocument(url);
           }
      }

Okay, save the applet as URL. Make the HTML file to view it. If you are a beginner I still think that loading an image on mouseover is better.  Make the image in a graphics program that states the description of the button and then make it load when you want it to.
0
 

Author Comment

by:jbird090897
ID: 1220983
Thanks
0
 

Author Comment

by:jbird090897
ID: 1220984
Thorner,
I thought i was done,
I compiled your code under Visualj++ and recieved the following error
undefined package 'Event' thats probably because the it doesn't have the java.awt.event in
it- so that solves that one.
And compiled in JDK1.2 i get 1 error
"Interface Actionlister of class URL no found"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:thorner
ID: 1220985
Check that your type ActionListener and not Actionlister.

"Interface Actionlister of class URL no found"
0
 

Author Comment

by:jbird090897
ID: 1220986
Thorner I did type Actionlistener on both all i did was copy what you have here.Have
you tried to compile the code. If you could compile it i'll just reinstall jdk and visualJ++
0
 

Expert Comment

by:thorner
ID: 1220987
Now, here's what I have but I can't get it to work. We're gonna have to leave it up to other experts I guess. I thought this would work but I guess not. The reason for the error messages before was because of the capital E in event. That was my fault.
This code has 1 error in it.

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.net.*;

public class URL extends Applet implements ActionListener
{      
      private Button link;
        private URL url;
        private String location;

        public void init()
        {
                location = "http://www.yoursitehere.com";
                url = new URL();
                   
                link = new Button("Click Here...");
                add(link);
                link.addActionListener(this);
        }

        public void actionPerformed(ActionEvent e)
        {
                URL url = (URL) e.getSource();
                getAppletContext().showDocument(url);
        }
}

0
 

Expert Comment

by:knollc
ID: 1220988
VJ++ doesn't support the new event model so forget ActionListener in J++.
0
 

Expert Comment

by:knollc
ID: 1220989
VJ++ doesn't support the new event model so forget ActionListener in J++.
0
 

Author Comment

by:jbird090897
ID: 1220990
ok true but what about jdk1.2?
0
 

Expert Comment

by:thorner
ID: 1220991
Jbird,
The ActionListener part of the program is fixed in the above code.  The only problem now is that the code in the actionPerformed method is incorrect.  I don't know why it doesn't work, but try compiling that for yourself and see what you get.
0
 
LVL 1

Accepted Solution

by:
cph earned 150 total points
ID: 1220992
Here is the working code (at least it compile ;):

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.net.*;

public class UrlApplet extends Applet implements ActionListener
{private Button link;
private URL url;
private String location;

public void init()
      {location = "http://www.sitehere.com";
         try {url = new URL(location);
              link = new Button("Click Here...");
              add(link);
              link.addActionListener(this);
           }
       catch (MalformedURLException BadURL)
            {//Anything you want
            }
        }

public void actionPerformed(ActionEvent e)
      {URL url = (URL) e.getSource();
         getAppletContext().showDocument(url);
        }
}

Note: Name your file the name of the class.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now