?
Solved

Little problem with Open File dialog

Posted on 2003-03-02
15
Medium Priority
?
323 Views
Last Modified: 2010-03-31
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
Comment
Question by:ticoldam12
[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
  • 4
  • 3
  • +2
15 Comments
 

Author Comment

by:ticoldam12
ID: 8052284
I posted "dialogoArchivo.getDirectory". This is in spanish. I forgot to translate it. this line is "dialogFile.getDirectory". Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8052490
>>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
 

Author Comment

by:ticoldam12
ID: 8052514
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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 86

Expert Comment

by:CEHJ
ID: 8052567
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
 

Author Comment

by:ticoldam12
ID: 8052605
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
 

Author Comment

by:ticoldam12
ID: 8052628
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
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 8052750
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
 

Author Comment

by:ticoldam12
ID: 8052956
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
 
LVL 30

Accepted Solution

by:
Mayank S earned 100 total points
ID: 8109235
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 8544861
How about rating it now?
0
 

Expert Comment

by:CleanupPing
ID: 9058979
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 9058993
Recommendation: Accept mayankeagle's comment as answer :-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9721212
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 9721638
Please go ahead with that recommendation.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

741 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