No se si te refieres a algo como esto:
Código PHP:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Testing
{
private JLabel lbl = new JLabel("Name = ");
public void buildGUI()
{
JButton btn = new JButton("Get Name");
final JFrame f = new JFrame();
f.getContentPane().add(lbl,BorderLayout.NORTH);
f.getContentPane().add(btn,BorderLayout.SOUTH);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
new MyDialog(Testing.this,f);
}
});
}
public JLabel getLabel()
{
return lbl;
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Testing().buildGUI();
}
});
}
}
class MyDialog
{
JDialog d;
JTextField tf = new JTextField(10);
Testing mainApp;
public MyDialog(Testing t,JFrame parent)
{
mainApp = t;
JButton btn = new JButton("OK");
d = new JDialog(parent);
d.getContentPane().add(tf,BorderLayout.NORTH);
d.getContentPane().add(btn,BorderLayout.CENTER);
d.setTitle("JDialog");
d.setModal(true);
d.pack();
d.setLocation(parent.getX()+150,parent.getY());
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
mainApp.getLabel().setText("Name = "+tf.getText());
}
});
d.setVisible(true);
}
}
Código PHP:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Testing
{
JLabel lbl = new JLabel("Name = ");
public void buildGUI()
{
JButton btn = new JButton("Get Name");
final JFrame f = new JFrame();
f.getContentPane().add(lbl,BorderLayout.NORTH);
f.getContentPane().add(btn,BorderLayout.SOUTH);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String retVal = new MyDialog(f).getName();
String temp = "";
if(retVal == null) temp = "Cancelled";
else if(retVal.equals("")) temp = "nothing entered";
else temp = "Name = "+retVal;
lbl.setText(temp);
}
});
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Testing().buildGUI();
}
});
}
}
class MyDialog
{
JDialog d;
String returnValue = null;
public MyDialog(JFrame parent)
{
JPanel p = new JPanel(new GridLayout(1,2));
JButton cancelBtn = new JButton("Cancel");
JButton okBtn = new JButton("OK");
p.add(cancelBtn); p.add(okBtn);
final JTextField tf = new JTextField(10);
d = new JDialog(parent);
d.getContentPane().add(tf,BorderLayout.NORTH);
d.getContentPane().add(p,BorderLayout.CENTER);
d.setTitle("JDialog");
d.setModal(true);
d.pack();
d.setLocation(parent.getX()+150,parent.getY());
d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
okBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
returnValue = tf.getText();
d.dispose();
}
});
cancelBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
d.dispose();
}
});
d.setVisible(true);
}
public String getName(){return returnValue;}
}
saludos