File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Preferred/Best Practice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Preferred/Best Practice" Watch "Preferred/Best Practice" New topic
Author

Preferred/Best Practice

Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Hello,

I have a GUI that creates an instance of another class that can create a JOptionPane under certain conditions to inform the user of something.

Is it best to pass in the JFrame to the constructor of that class so I can send that to the JOptionPane like so:



or do something like this with a static method:



The reason I want the GUI frame is so my dialog boxes pop up on top of that frame, instead of the center of the screen.

Perhaps there is another way of doing this?

I don't want to "clutter" up the constructor when the use of that reference may never be used.

Thanks for the help

BD


I've got just enough Java knowledge to royally screw everything up. :-)
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

Sounds like you're mixing responsibilities.

What is a non-GUI class doing invoking a dialogue? You should adhere to the MVC principle. Maybe if you explain what the idea behind the dialogue and the middle-man class is, we can give you some advice.
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
I appreciate the response Stephan.

I am currently in school earning a CS degree, and I have yet to even hear of MVC. I had an intro to OO course last year that used Java, and I've got one more OO course that uses C++ in the Spring. Perhaps MVC is covered in that course.

I am trying to learn Java so I'll have a skill when I leave school so that I can actually DO something.

Anyway, I'll read up on MVC and that may make this question I posted moot.

Cheers

BD
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
I suggest you go through the documentation for JOptionPane and its methods. I think you will find that in most cases the first parameter sets the location on screen where the option pane dialogue appears. You will probably also find a Java Tutorials link, which I recommend you follow. It will help you a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Preferred/Best Practice