Link to home
Start Free TrialLog in
Avatar of rakhras
rakhras

asked on

Position of a Java applet

Hi,

I'm writing a java applet that will be embedded
in an HTML page at an aribtrary position.

Within the java applet code, I need to know the
absolute screen coordinates of the applet.
Any ideas?

Thanks,
Ralph
Avatar of zicai
zicai

As heyhey said,

1) You cannot do that in pure Java
2) try to use Java Script to do that.

Good luck!
Yours sincerely
Zicai
ASKER CERTIFIED SOLUTION
Avatar of masato
masato

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wah.., masato

It's true.. Maybe I didn't get the right meaning from
heyhey's words.. Sigh:(


Thank you masato, and thank you rakhras for posting the
question!

All the best to you all!
Zicai

Avatar of rakhras

ASKER

I tried component.getLocationOnScreen() in my java applet
but the J++ compiler complained that:

error J0072: 'getLocationOnScreen' is not a member of class 'Component'

any ideas?
Thanks,
Ralph

Hi Ralph,

Since you are writing an Applet and the Applet class is inherited from the Component class, you don't need to put the "component." in front.
Just call the getLocationOnScreen() method as follows:

class Foo extends Applet
{
    public void init()
   {
      Point p = getLocationOnScreen();
      .........
   }
}

Please try.
Sorry,
The sample code I've posted is not correct. Please try the following sample Applet instead.
-----------------------------
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class Sample extends Applet implements ActionListener
{
      Button button1;

      public void init()
      {
            button1 = new Button("Location");
            add(button1);
            button1.addActionListener(this);
      }

      public void actionPerformed(ActionEvent e)
      {
            System.out.println(getLocationOnScreen());
      }
}
-----------------------------


Avatar of rakhras

ASKER

same problem ...
G:\java\MqCalendar\test.java(22,23) : error J0049: Undefined name 'getLocationOnScreen'

does this compile for you?

Thanks,
Ralph
I guess your J++ is not supporting the JDK 1.1 yet. Please check the supported Java version because getLocationOnScreen() method is implemented from JDK1.1.  I can compile the sample applet without any problem, but I'm using Sun's JDK1.1.7B.
Hi Ralph,
I found a infomation how to use J++ with the JDK 1.1.

http://www.javaworld.com/javaworld/javatips/jw-javatip25.html

You may want to try this...