Link to home
Start Free TrialLog in
Avatar of ticoldam12
ticoldam12

asked on

Little problem with Open File dialog

This is the code im using, i would like you to test it. A very small "frame" opens in the top left corner in the screen.

public class OpenFile extends Frame {

Frame container = new Frame();
     String path = "";
     public OpenFile() {

FileDialog dialogFile = new FileDialog (container, "Choose file", FileDialog.LOAD);

dialogFile.setVisible (true);
String name = dialogFile.getFile();
String directory=dialogoArchivo.getDirectory();

          if (name != null);
          {
          path = directory + name;
          System.out.println(path);
         
this.addWindowListener (new WindowAdapter () {
                         public void windowClosing(WindowEvent e) {
                        hide();
                }
          });
          }
          hide();
     }
}


I dont know why a little frame appears in the corner of the screen. What king of changes do i have to make to solve this problem???
Avatar of ticoldam12
ticoldam12

ASKER

I posted "dialogoArchivo.getDirectory". This is in spanish. I forgot to translate it. this line is "dialogFile.getDirectory". Thanks
Avatar of CEHJ
>>Frame container = new Frame();

The above is redundant (you're already extending Frame) and will cause problems

So

>>FileDialog dialogFile = new FileDialog (container, "Choose file", FileDialog.LOAD);


should be

FileDialog dialogFile = new FileDialog (this, "Choose file", FileDialog.LOAD);

You will of course need to set a size for OpenFile before you show it.


Thank you for your help CEHJ....I solved the redundancy problem...but im still having problems. A frame appears in the top left corner of the screen...
How are you using your OpenFile class? By the way, you'd be better to have a showDialog method or something, rather than trying to show the dialog in the constructor
Im calling the OpenFile this way: (of course this is in other class)

OpenFile select = new OpenFile();
select.show();
          if( (select.path).equals("nullnull") {
          //No action
                }
           else{
           ..........................
           }

Do you tell me to use select.showDialog instead of select.show()...????

How can i make a showDialog method???
Im calling the OpenFile this way: (of course this is in other class)

OpenFile select = new OpenFile();
select.show();
          if( (select.path).equals("nullnull") {
          //No action
                }
           else{
           ..........................
           }

Do you tell me to use select.showDialog instead of select.show()...????

How can i make a showDialog method???
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Hey CEHJ...the problem is solved now!
The problem was the line "select.show();"
why?
Because the Open file dialog opens by itself by only making the contructor of the class OpenFile. That line shows another frame.

Well, thank you so much, you have given me a clearer situation of my problem...
ASKER CERTIFIED SOLUTION
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
How about rating it now?
ticoldam12:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
Recommendation: Accept mayankeagle's comment as answer :-)
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split between mayankeagle and CEHJ.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TimYates
EE Cleanup Volunteer
Please go ahead with that recommendation.