Solved

MouseOver

Posted on 1998-05-13
16
318 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

708 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

15 Experts available now in Live!

Get 1:1 Help Now