Results 1 to 3 of 3
  1. #1
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

    Default A frame and a dialog

    Say I have a JFrame with a button in it. I want a JDialog to appear when I click the button.

    I could do this by writing another class that creates the JDialog and then by making an object of that class from my main class with the JFrame. But could I not also just create the JDialog in the original class? It wouldn't look very nice obviously; the JDialog is about 40 lines long. Is that the only reason for not wanting to do so?

    My question is, should you separate code into classes for purely 'aesthetic' seasons?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    If the dialog were simple and quite obviously dependent on the calling class, and also obviously that this will not change in the forseeable future, then I don't see any problem with keeping the code within the calling class if the class isn't too big. otherwise, it would be better to place the other GUI code in another class.

    A note here though: I almost always create the JDialog object itself in the calling class since this creation usually needs to be controlled by the calling class, but I place the code that creates the JPanel that will serve as the JDialog's contentPane in its own class.

  3. #3
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

    Default

    Will in my case it will make it slightly simpler because I need to access data from JTextFields in the JDialog...

Similar Threads

  1. GUI new frame
    By billbo123 in forum New To Java
    Replies: 15
    Last Post: 03-02-2009, 04:24 AM
  2. frame
    By arunkumarinfo in forum NetBeans
    Replies: 0
    Last Post: 02-07-2009, 10:26 AM
  3. Frame to other Frame
    By Aswq in forum New To Java
    Replies: 2
    Last Post: 07-19-2008, 04:27 PM
  4. Example of SWT Dialog
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-09-2008, 12:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •