Link to home
Start Free TrialLog in
Avatar of Deladier
Deladier

asked on

Get data from Dialog Window.

Hello, I have a problem with a Dialog Window, it has a TextField and a Button in order to input a String. Till here, everything works fine, but the problem is How to send this String value to parent window ?.
Here's the code:

 import java.awt.*;


public class window3 extends java.applet.Applet {
 Frame marco;
 Button abre;
 TextArea ta;

 
   
 public void init() {
  resize(140, 100);
  ta = new TextArea(3,10);
  abre = new Button("Open window");
  ta.appendText(nuevoNom);
  add(ta);
  add(abre);
  marco = new MiMarco("Change Name Window");
  marco.resize(380,50);
  marco.hide();
 }

 public boolean action(Event evt, Object algo) {
  Object target = evt.target;
 
  if(target == abre) {
    marco.show();
   return true;
  }

  return false;
 }
 
}
 



 
 class MiMarco extends Frame {
  String nuevoNom;
  TextField newnom;
  Button cambianom;
  Label cambiarn;

  MiMarco(String title) {
   super(title);
   setLayout(new GridLayout(1,1));
   cambiarn = new Label("New name:");
   newnom = new TextField(24);
   cambianom = new Button("Accept");
   add(cambiarn);
   add(newnom);
   add(cambianom);
  }
 
  public boolean action(Event evt, Object algo) {
   Object target = evt.target;

   if(target == cambianom) {
     nuevoNom = newnom.getText();
     newnom.setText("");
     hide();
    return true;
   }
   
   return false;
  }  
 
 }


In other words, I'd like to use "nuevoNom" String value in public class window3, How do I do that?.

   Thanks a lot.
ASKER CERTIFIED SOLUTION
Avatar of msmolyak
msmolyak

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Deladier
Deladier

ASKER

Sorry, I'm still learning about Frames and Dialogs. Do you know where I can get more  examples related?.

   Thanks.
Two points:
- Frame is usually the main application window, while the Dialog is a subordinate window which always requires a frame as a parent.
- Dialog can be modal. Modal dialog when displayed (by setVisible(true)) immediately blocks the calling thread (usually that means that you cannot do anything until you close the dialog) which continues only after you close the dialog (with setVisible(false)).

I am sure Java Tutorial on Javasoft's Web (www.javasoft.com) site talks about that.