Solved

Dialog info (take 2)

Posted on 1998-06-30
4
174 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
Comment Utility
After
       testlog(Frame parent,DataChanger dc)  {    
                    super(parent,"Test",true);
add
                    this.dc = dc;
0
 

Author Comment

by:mbunkows
Comment Utility
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
Comment Utility
You have to pass it twice unless you can be assured that your DataChanger is a parent frame.
0
 

Author Comment

by:mbunkows
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

772 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

11 Experts available now in Live!

Get 1:1 Help Now