What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Java question

Java question
Author: Message:
saralk
Veteran Member
*****

Avatar

Posts: 2598
Reputation: 38
35 / Male / Flag
Joined: Feb 2003
O.P. Java question
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.
The Artist Formerly Known As saralk
London · New York · Paris
Est. 1989
02-06-2008 03:46 PM
Profile PM Find Quote Report
foaly
Senior Member
****

Avatar

Posts: 718
Reputation: 20
38 / Male / Flag
Joined: Jul 2006
RE: Java question
I don't really get the problem but can't you do something like

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

02-06-2008 04:10 PM
Profile E-Mail PM Find Quote Report
saralk
Veteran Member
*****

Avatar

Posts: 2598
Reputation: 38
35 / Male / Flag
Joined: Feb 2003
O.P. RE: Java question
You can't do that because the code is executed in the actionPerformed function which can't have a return value.
The Artist Formerly Known As saralk
London · New York · Paris
Est. 1989
02-06-2008 04:23 PM
Profile PM Find Quote Report
foaly
Senior Member
****

Avatar

Posts: 718
Reputation: 20
38 / Male / Flag
Joined: Jul 2006
RE: Java question
where do you need the data to be?
02-06-2008 04:33 PM
Profile E-Mail PM Find Quote Report
saralk
Veteran Member
*****

Avatar

Posts: 2598
Reputation: 38
35 / Male / Flag
Joined: Feb 2003
O.P. RE: Java question
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.
The Artist Formerly Known As saralk
London · New York · Paris
Est. 1989
02-06-2008 04:42 PM
Profile PM Find Quote Report
foaly
Senior Member
****

Avatar

Posts: 718
Reputation: 20
38 / Male / Flag
Joined: Jul 2006
RE: Java question
probably better to use JOptionPane.showInputDialog() then...
instead of the dialog with the listener... if that is an option...

This post was edited on 02-06-2008 at 04:52 PM by foaly.
02-06-2008 04:51 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On