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

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???
0
ticoldam12
Asked:
ticoldam12
  • 5
  • 4
  • 3
  • +2
2 Solutions
 
ticoldam12Author Commented:
I posted "dialogoArchivo.getDirectory". This is in spanish. I forgot to translate it. this line is "dialogFile.getDirectory". Thanks
0
 
CEHJCommented:
>>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.


0
 
ticoldam12Author Commented:
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...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CEHJCommented:
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
0
 
ticoldam12Author Commented:
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???
0
 
ticoldam12Author Commented:
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???
0
 
CEHJCommented:
Make a separate void showDialog method in OpenFile that simply calls show on the FileDialog you've created.

When you create an instance of OpenFile you must give it a size.
0
 
ticoldam12Author Commented:
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...
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Fellow, your OpenFile class is already extending Frame and so you really don't need to declare the Frame object 'container' as you've done.

class OpenFile extends Frame // this will be the parent-frame for the dialog box
{
  OpenFile () // constructor ()
  {
    super ( "FILE DIALOG DEMO" )
    resize ( 800, 600 ) ; // for setting size of the frame window
    show () ;
    FileDialog f = new FileDialog ( this, "Files in this folder.." ) ;
    f.show () ;

  } // end of constructor ()

} // class definition over

To instantiate the frame window, simply write:

new OpenFile () ;

and a frame window of size 800 X 600 will open with the title "FILE DIALOG DEMO", and a file dialog will open along with it.

Mayank.


0
 
Mayank SAssociate Director - Product EngineeringCommented:
How about rating it now?
0
 
CleanupPingCommented:
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.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Recommendation: Accept mayankeagle's comment as answer :-)
0
 
TimYatesCommented:
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
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Please go ahead with that recommendation.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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