Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get data from Dialog Window.

Posted on 1998-07-01
3
Medium Priority
?
211 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 120 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

824 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