Shoutbox

Java question - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Java question (/showthread.php?tid=81486)

Java question by saralk on 02-06-2008 at 03:46 PM

Hi,

I need to create a simple Java application for my coursework, and i'm having a little trouble.

Basically, i've created a class that deals with all the GUI stuff. And part of the GUI requires a popup dialogue window, that allows for the creation of a new entry.

I don't want to deal with any of the database stuff in the GUI class, so I want the function to return the data that was inputted in the dialogue box when you press OK.

Here is a bit of the code I wrote...

code:
public Contact addContactWindow() {
//opens an add contact dialouge box, returns a Contact object
//SNIP
   
{ //listener for the ok button
  class MenuItemListener implements ActionListener {
   public void actionPerformed(ActionEvent event) {
    //code goes here
   }
  }
  ActionListener listener = new MenuItemListener();
  okButton.addActionListener(listener);
}

}

So when the ok button is pressed, the code in the actionPerformed function will be executed. I can construct a Contact object easily, however I can't figure out how to return it.
RE: Java question by foaly on 02-06-2008 at 04:10 PM

I don't really get the problem but can't you do something like

code:
contact1.data = textarea.getText();
return contact1.toString();


RE: Java question by saralk on 02-06-2008 at 04:23 PM

You can't do that because the code is executed in the actionPerformed function which can't have a return value.


RE: Java question by foaly on 02-06-2008 at 04:33 PM

where do you need the data to be?


RE: Java question by saralk on 02-06-2008 at 04:42 PM

Well basically, the way I want it to work is that addContactWindow() will be called from a different class, and then once the user has clicked OK, the class that called it will know what the Contact object that was returned is.


RE: Java question by foaly on 02-06-2008 at 04:51 PM

probably better to use JOptionPane.showInputDialog() then...
instead of the dialog with the listener... if that is an option...