Getting data from a JDialog

Z

zelao.itu

Hi everybody, I'm doing an app where I need to get a value from a
variable of another JDialog.

My MainFrame call the class SelectClient, where SelectClient has a
JTable with all data. when user double click over the table it supose
to return the data of the selected cell.
I tried like this :

//main.java

public void actionPerformed(ActionEvent e) {
if(e.getSource() == btCad) {
SelectClient tmp = new SelectClient(this);
while(tmp.running) {
try {
wait();
} catch ( InterruptedException e1) { }

}

String data = tmp.data;
tmp.dispose();

//SelectClient.java
class SelectClient extends JDialog ....
public void mouseClicked(MouseEvent e) {
if (e.getSource() == tableClients) {
if (e.getClickCount() == 2) {
data = tableModel.getPrimaryKey(1);
running = false;
notifyAll();
}
}
}
 
A

Andrew Thompson

Hi everybody, I'm doing an app where I need to get a value from a
variable of another JDialog.

Is it modal? When do you want the data, after it
is closed, or as it is selected? Both those things
might impact my answer, but your code snippets
do not cover them.

Note that one thing that would explain the first,
and possibly explain the second thing I asked,
as well as two or three other questions that might
be relevant, would be an SSCCE..
<http://www.physci.org/codes/sscce>

(As an aside, did you realise there is a group devoted
to GUI matters? It has a lower volume of people who
are more expert in discussions related to GUI's. It is
comp.lang.java.gui )

Andrew T.
 
I

Ian Wilson

I have set followups to comp.lang.java.gui (reset it if you don't like
this).

Hi everybody, I'm doing an app where I need to get a value from a
variable of another JDialog.

My MainFrame call the class SelectClient, where SelectClient has a
JTable with all data. when user double click over the table it supose
to return the data of the selected cell.
I tried like this :

//main.java

public void actionPerformed(ActionEvent e) {
if(e.getSource() == btCad) {
SelectClient tmp = new SelectClient(this);

This next part shouldn't be needed normally.
while(tmp.running) {
try {
wait();
} catch ( InterruptedException e1) { }

}

String data = tmp.data;
You don't say what you expected and what actually happened.
I'd use a debugger or insert a debug statement like
System.out.println("dialog returned data: '"+data+"'.");

tmp.dispose();
I don't think you need to explicitly dispose of object references. Just
make sure their scope is limited and they should be garbage collected
automatically. The Sun tutorials on Dialogs have the dialog do
..setVisible(false) when the OK/Cancel (or equivalent) buttons are
pressed. This seems to be sufficient - I'd do that inside your
SelectClient class.

//SelectClient.java
class SelectClient extends JDialog ....
public void mouseClicked(MouseEvent e) {
if (e.getSource() == tableClients) {
if (e.getClickCount() == 2) {
data = tableModel.getPrimaryKey(1);

My guess (since you don't provide a complete program) is that
getPrimaryKey(1) doesn't do what you think it does.
running = false;
notifyAll();
}
}
}

Your code is indented using a mix of tabs and spaces, which is why it
looks a mess in the newsgroup. I configured my IDE/Editor to expand tabs
to spaces - it avoids this problem. You might like to try that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top