[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Dialog info (take 2)

Posted on 1998-06-30
4
Medium Priority
?
215 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

Technology Partners: 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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

650 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