Solved

Get data from Dialog Window.

Posted on 1998-07-01
3
197 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countHi2 challenge 7 44
word0 challenge 4 54
wordmultiple challenge 12 93
VB Script to add site to Java Exception List 4 19
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now