Solved

MouseOver

Posted on 1998-05-13
16
338 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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
 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

803 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