This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Preferred/Best Practice

 
Bd Howard
Greenhorn
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stephan van Hulst
Bartender
Pie
Posts: 5812
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic