Solved

Get data from Dialog Window.

Posted on 1998-07-01
3
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

749 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