• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 714
  • Last Modified:

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
0
rakhras
Asked:
rakhras
  • 5
  • 2
  • 2
1 Solution
 
zicaiCommented:
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
0
 
masatoCommented:
You can get the screen position using getLocationOnScreen() method.
0
 
zicaiCommented:
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

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
rakhrasAuthor Commented:
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

0
 
masatoCommented:
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.
0
 
masatoCommented:
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());
      }
}
-----------------------------


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

does this compile for you?

Thanks,
Ralph
0
 
masatoCommented:
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.
0
 
masatoCommented:
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...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now