Solved

Get data from Dialog Window.

Posted on 1998-07-01
3
200 Views
Last Modified: 2010-03-30
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.
0
Comment
Question by:Deladier
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
msmolyak earned 40 total points
ID: 1224306
If I understand it correcrly, MiMacro is the dialog which accepts teh string which you want to display in an applet (Why do you extend a Frame, not a dialog then?).

Why do you instantiate MiMacro after you set the string in the applet. You should probably first create the dialog get the string and then use it in the applet.

public void init() {

      marco = new MiMarco("Change Name Window");
      marco.resize(380,50);
//      marco.hide();  you do need to call hide here, you can do it in the Dialog's action method.
     
     // make sure the dialog is modal, then the processing will not
     // continue until you hide it.

    // Now get the string (getString() is the method in MiMacro which returns the string).
      nuevoNom = macro.getString();
      resize(140, 100);
      ta = new TextArea(3,10);
      abre = new Button("Open window");
      ta.appendText(nuevoNom);
      add(ta);
      add(abre);
     }
0
 

Author Comment

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

   Thanks.
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1224308
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.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 86
Java JRE greater than 1.6 5 62
egit plugin on eclipse 8 63
CSV file parsing thru Java 13 31
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question