?
Solved

Dialog info (take 2)

Posted on 1998-06-30
4
Medium Priority
?
207 Views
Last Modified: 2010-03-30
I asked a question earlier about passing data between dialog and parent with events.
I have tried to implement that solution which seemed to be fairly straight forward (and im sure was)
the following code works until i try to send data through an event if the data is transferred right away (through the constructer) i have no problem.
Also creating the new instance of the dialog seems a bit strange to have to pass the parent (itself) twice...
I seem to be real close to getting this accomplished, I just need a gentle push (or violent shove (you choose)) in the right direction.

The code is as follows:
(please excuse the non-conventional class/file names .. this was suppose to be a quick test)

/** testGUI is the main Frame that displays dialog info

//testGUI.java
*/

import java.awt.*;
import java.awt.event.*;


public class testGUI extends Frame implements DataChanger  {
    TextArea sentence;
    Button button1;
    TextField field;
        testGUI()  {
                this.setBackground(Color.lightGray);
                this.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
                field= new TextField(10);
                this.add(field);
                sentence= new TextArea(10,75);
                sentence.setEditable(false);
                this.add(sentence);
                button1=new Button("TRY");
                button1.addActionListener(new B1());
                this.add(button1);
                }

        public String getListData()  {
                return field.getText();
                }

        public void setTextData(String data)  {
                sentence.append("Received from dialog: " + data + "\n");
                }
        class B1 implements ActionListener  {
                public void actionPerformed(ActionEvent e)  {
                        testlog d= new testlog(testGUI.this,testGUI.this);
                        d.show();
                        }
                }

        public static void main(String[] args)  {
                Frame f= new testGUI();
                f.addWindowListener(new WindowAdapter()  {
                        public void windowClosing(WindowEvent e)
                                {System.exit(0);}
                        });
                f.pack();
                f.setVisible(true);
                }
        }

/** testlog is the class that implements the dialog box and
handles the events

//testlog.java
*/


import java.awt.*;
import java.awt.event.*;

public class testlog extends Dialog  {
    Button ok;
    Button cancel;
    TextField text;
    DataChanger dc;

        testlog(Frame parent,DataChanger dc)  {  
                super(parent,"Test",true);
                this.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
                text= new TextField(10);
                this.add(text);
                ok= new Button("OK");
                ok.addActionListener(new BOK());
                cancel= new Button("CANCEL");
                cancel.addActionListener(new BCAN());
                this.add(ok);
                this.add(cancel);
                text.setText(dc.getListData());
                dc.setTextData("from constructer");    //works
                this.pack();
                }
        class BOK implements ActionListener  {
                public void actionPerformed(ActionEvent e)  {
                        dc.setTextData("from event");    //does not work
                        }
                }
        class BCAN implements ActionListener  {
                public void actionPerformed(ActionEvent e)  {
                        testlog.this.dispose();
                        }
                }
        }
       
/**
DataChanger is the the interface
//DataChanger.java
*/
public interface DataChanger  {
        public String getListData();
        public void setTextData(String data);
        }
0
Comment
Question by:mbunkows
[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
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
msmolyak earned 120 total points
ID: 1224187
After
       testlog(Frame parent,DataChanger dc)  {    
                    super(parent,"Test",true);
add
                    this.dc = dc;
0
 

Author Comment

by:mbunkows
ID: 1224188
ahh haaa
major oversight on my part

you answered my main question but if you have any comments on the question about having to pass both a Frame and a DataChanger (via testGUI.this) that would be great
it seems to be repetitious

Thanks

0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1224189
You have to pass it twice unless you can be assured that your DataChanger is a parent frame.
0
 

Author Comment

by:mbunkows
ID: 1224190
Ahhh great thanks
Let me know if you didnt get the right amount of points that were originally assigned
My last couple questions have that problem
:(


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month15 days, 9 hours left to enroll

743 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