?
Solved

Locate window dialog

Posted on 2003-04-01
37
Medium Priority
?
227 Views
Last Modified: 2010-03-31
I'm opening a window dialog from an applet and, by default, it is located in the top-left of screen coordinates.
Actually I can locate this window with super.setLocation(X,Y), but I'd prefer to relate it with the main window position.
How ca I get that position? (parent.getLocation() doesn't work!)
0
Comment
Question by:joktur
[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
  • 19
  • 15
  • +2
37 Comments
 
LVL 9

Expert Comment

by:Ovi
ID: 8245877
why parent.getLocation()?
you should use yourDialog.getLocation();
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8245901
and yourDialog.getLocationOnScreen()
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8245905
Is not necesary to make calls to parent since those methods are public and inherited by your dialog, especialy if the parent is null.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:joktur
ID: 8245936
I'm looking for a location to set my dialog. For this I'll consider the main window position, where is the applet.
i.e, I know dialog's location (yourDialog.getLocation();) but I'm looking for parent's dialog position.
Thks
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8246044
and who is the parent dialog? the browser window?
0
 

Author Comment

by:joktur
ID: 8246051
I'm looking for a location to set my dialog. For this I'll consider the main window position, where is the applet.
i.e, I know dialog's location (yourDialog.getLocation();) but I'm looking for parent's dialog position.
Thks
0
 

Author Comment

by:joktur
ID: 8246061
yes. It's where dialog comes.
0
 
LVL 1

Expert Comment

by:loukas34
ID: 8246069
try this

public class window ....
{
 ...
 public set_Location(int x,int y)
 {
  this.setLocation(x,y);
 }
}

public class my_applet ...
{
 ...
window.set_Location((int)this.getLocation().getX(),(int)this.getLocation().getY());
}
0
 

Author Comment

by:joktur
ID: 8246071
yes. It's where dialog comes.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8246084
use yourApplet.getLocation() or yourApplet.getLocationOnScreen()
0
 

Author Comment

by:joktur
ID: 8246102
yes. It's where dialog comes.
0
 
LVL 4

Expert Comment

by:thanassis
ID: 8246109
Yes loukas the great is write!

perfect solution!

Elladara!!!
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8246134
like I've said before, use yourApplet.getLocation() or yourApplet.getLocationOnScreen() to determine the applet location, and compute accordingly the desired location of the window.
0
 

Author Comment

by:joktur
ID: 8246135
yes. It's where dialog comes.
0
 

Author Comment

by:joktur
ID: 8246210
It looks easy and logic but doesn't work.
Here's the sequence:

public mainClass extends Applet{

  ...
 
  myClassDialog d= new myClassDialog(this);
  d.show();

}

class myClassDialog extends Dialog{

  myClassDialog(mainClass p);

  //Now i'd like to locate this dialog related to p
  //1: absolute location
  this.setLocation(500,500); //it works
  //2: relative location
  this.setLocation(p.getLocation().getX(),p.getLocation().getY()); //dialog doesn't open
 

}
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8246230
have you tried with getLoationOnScreen()?
0
 

Author Comment

by:joktur
ID: 8246238
It looks easy and logic but doesn't work.
Here's the sequence:

public mainClass extends Applet{

  ...
 
  myClassDialog d= new myClassDialog(this);
  d.show();

}

class myClassDialog extends Dialog{

  myClassDialog(mainClass p);

  //Now i'd like to locate this dialog related to p
  //1: absolute location
  this.setLocation(500,500); //it works
  //2: relative location
  this.setLocation(p.getLocation().getX(),p.getLocation().getY()); //dialog doesn't open
 

}
0
 

Author Comment

by:joktur
ID: 8246254
It looks easy and logic but doesn't work.
Here's the sequence:

public mainClass extends Applet{

  ...
 
  myClassDialog d= new myClassDialog(this);
  d.show();

}

class myClassDialog extends Dialog{

  myClassDialog(mainClass p);

  //Now i'd like to locate this dialog related to p
  //1: absolute location
  this.setLocation(500,500); //it works
  //2: relative location
  this.setLocation(p.getLocation().getX(),p.getLocation().getY()); //dialog doesn't open
 

}
0
 

Author Comment

by:joktur
ID: 8246270
> have you tried with getLoationOnScreen()?
yes. Doesn't work.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8246296
I must leave now. If you don't have a solution until tomorrow, I will try to help you.
0
 

Author Comment

by:joktur
ID: 8246332
> have you tried with getLoationOnScreen()?
yes. Doesn't work.
0
 

Author Comment

by:joktur
ID: 8246359
> have you tried with getLoationOnScreen()?
yes. Doesn't work.
0
 
LVL 92

Expert Comment

by:objects
ID: 8249783
There is no way to determine the location of the browser window that I know of.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8251499
Sorry, but my applet works fine and opens a MODAL dialog relatively to the position of the applet on the screen. The dialog behaves like a native modal dialog, in the sense that you cannot click nothing until you close'it. Tested in IE and Mozilla.


/*
 * Created on Apr 2, 2003
 *
 * To change this generated comment go to
 * Window>Preferences>Java>Code Generation>Code Template
 */

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @author ovi
 */
public class AppletLocation extends Applet {
     private Button open = new Button("Open");
     
     public void init() {          
          setLayout(new BorderLayout());
          add(open, BorderLayout.SOUTH);
          open.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent arg0) {
                    openDialog();
               }
          });
     }

     private void openDialog() {
          Container c = this;
          while (c != null && !(c instanceof Frame)) {
               c = c.getParent();
          }
          if (c == null)
               c = new Frame();
          Frame parent = (Frame) c;
         
          int w = 150;
          int h = 150;
          int x = parent.getLocationOnScreen().x;
          int y = parent.getLocationOnScreen().y;
          final Dialog dlg = new Dialog(parent, "Test", true);
          dlg.addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent we) {
                    dlg.setVisible(false);
                    dlg.dispose();
               }
          });
          dlg.setSize(w, h);
          dlg.setLocation(x - 20, y - 20);
          dlg.setVisible(true);
          System.out.println("Should not get here when dlg is visible");
     }
}
0
 
LVL 9

Accepted Solution

by:
Ovi earned 200 total points
ID: 8251643
If you want to determine the location of the browser window, you should try to get'it thru JavaScript and with LiveConnect to send'it to the applet.
0
 

Author Comment

by:joktur
ID: 8252094
Thanks for your help.
I'll implement a thread to accept inputs from js. It's easy and works.
Best regards
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8252132
mee too. The applet onscreen location is not enough for you?
0
 

Author Comment

by:joktur
ID: 8252144
yes, it's enough.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8252162
I believe there is no thread necesary, since you need those coordinates only when you make the dialog visible.
0
 

Author Comment

by:joktur
ID: 8252165
yes, it's enough.
0
 

Author Comment

by:joktur
ID: 8252168
yes, it's enough.
0
 

Author Comment

by:joktur
ID: 8252213
That's right, I can it on fly.
This is a personal project to public my own java/GIS develops. You can look it through
http://www.portugalturismo.net > (pt only, sorry) MAPAS > e.g. Portugal > <Find icon>
30k Java1 based
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8252396
That's realy nice!

I have some suggestions:
1. You should implement a little doublebuffering to avoid flickering of the applet.
2. Put all classes in a jar file, it will load more quickly. Right now I have a very poor connection.
3. When you move around the map would be interesting if I can press and hold a arrow and the image will move herself, and not by many clicks.

:-) hope do't get me wrong, this are just few opinions. But there is a nice applet.
0
 

Author Comment

by:joktur
ID: 8252444
Thks for your suggestions.
1. (doublebuffering) I've done it creating an image, but it becames the re-rendering slow.
2. (jar) ok
3. (pan) easy with buffers

Have you seen the Dialog?
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8253199
no
0
 

Author Comment

by:joktur
ID: 8253223
The 8th tool button from the left aims to open it.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 8253868
I see'it now, but you are not using the applet coordinates yet :).

A more direct connection with me : ovi@sec.co.ro
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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…
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 about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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