?
Solved

Position of a Java applet

Posted on 1999-08-22
9
Medium Priority
?
706 Views
Last Modified: 2013-11-23
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
Comment
Question by:rakhras
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
9 Comments
 
LVL 2

Expert Comment

by:zicai
ID: 1248798
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
 
LVL 1

Accepted Solution

by:
masato earned 100 total points
ID: 1248799
You can get the screen position using getLocationOnScreen() method.
0
 
LVL 2

Expert Comment

by:zicai
ID: 1248800
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:rakhras
ID: 1248801
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
 
LVL 1

Expert Comment

by:masato
ID: 1248802
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
 
LVL 1

Expert Comment

by:masato
ID: 1248803
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
 

Author Comment

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

does this compile for you?

Thanks,
Ralph
0
 
LVL 1

Expert Comment

by:masato
ID: 1248805
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
 
LVL 1

Expert Comment

by:masato
ID: 1248806
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…
Suggested Courses

718 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