Solved

Dialog info (take 2)

Posted on 1998-06-30
4
205 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 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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…
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 about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

690 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