• Post Reply Bookmark Topic Watch Topic
  • New Topic

JDialog for capturing user input

 
Bob Sale
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use dialogs to capture user inputs that will be passed to another part of a program. The application is image editing. I have a dialog class and methods to display specific dialogs and capture associated user inputs. Each dialog window contains a variety of radio buttons and sliders to collect string and int data. The controls work fine but I cannot pass the user selections to other parts of the program upon clicking an OK button.
The structure of the dialog class is:

public class Dialogs extends JWindows {
some code
public void rotateDialog(){
code specific to this dialog
}
public void picassoDialog(){
code specific to this dialog
}
public void grayscaleDialog(){
code specific to this dialog
}

In one working design, I do the editing within the OK button's actionPerformed method. Although this works, I feel that from a design point of view, this is not the best approach. I think that the dialog boxes should be for specifying/capturing the user's wishes and that the actual execution should be done in another part of the program dedicated to editing processes. However, I cannot figure out how to pass data from a dialog box when OK is clicked. Since actionPerformed is of type void, return cannot be used, variables declared within actionPerformed are not visible outside that method, and variables declared outside of actionPerformed must be final to be visible by actionPerformed and hence their values cannot be changed.

Does anyone have guidance or suggestions? Thanks.


 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Bob Sale
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reminding me of this tutorial. I think that showInputDialog may come close to what I need. I will check it out and report back.
 
Darryl Burke
Bartender
Posts: 5153
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always remember that the message parameter to JOptionPane's static methods can be any Object. When you pass a Component like a populated JPanel, it is added to the JOptionPane.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!