Solved

Dialog info (take 2)

Posted on 1998-06-30
4
182 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
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
msmolyak earned 30 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
reasons why a "inside Menu" would not appear for a web server 6 56
@SBGen Method 3 35
Requested array size exceeds VM limit 3 84
simple java question 3 44
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…
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 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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

914 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

15 Experts available now in Live!

Get 1:1 Help Now