Solved

passing info from dialog

Posted on 1998-06-16
2
176 Views
Last Modified: 2010-03-30
Im writing a graphing program that has default headings when the user starts the program.  I wanted to give the
user the ability to change the heading text if they so desired.
So I created a series of menu selections to allow the user to change the text of the various headings.
When the user selects one of these menu selections (say the main heading) a dialog box appears asking for
the text of the new heading.
There is also an OK and a CANCEL button on the dialog box...
My problem is how do I send the info that is entered in the textfield back to the original frame so I can call the appropriate method to erase the main heading and draw the new one
And do I need to use the AWTEventMulticaster to assign all the events to the dialog itself (instead of the components in it) and go from there?

I can produce some code to look at if need be however it is fairly long and its kind of a generic question.

Also does anyone know where I can find some freeware classes for graphing or better yet just some algorithms so i dont have to "reinvent the wheel"?  (I know this is really a separate question but i thought if someone knew of a site off the top of their head... I suppose I would learn a lot more if i did it myself.. although it probably wouldnt be the most efficient way)

Thanks in advance
0
Comment
Question by:mbunkows
2 Comments
 
LVL 4

Accepted Solution

by:
evijay earned 100 total points
ID: 1223297
This is a problem of implementing preference Changer. It can be done by seperation of concerns and responsibilities.

I think you have a main graphing class which has a paint method and which stores the headings and other state info that need to render the graph.
Lets call this as

Grapher



Your grapher class should implement PreferenceModal interface which has methods to get/set the current graphing preferences.

Now, you have another class called PreferenceCustomizer Which displays a dialog containing user preferences and takes the details. PreferenceCustomizer takes an object that implements PreferenceModal as its constructor. It displays the dialog , populates current preferences using get methods of PreferenceModal object and when user changes the preferences, it invokes the methods on PreferenceModal object.Now,  going for code


public interface PreferenceModal {
   public String getHeading ();
   public void setHeading(String s);
  // add other preferences here

}

public class Grapher implements PreferenceModal {
   public String getHeading () {
            // implementation - may get the variable from a member variable
  }
   public void setHeading(String s){
     //implementation - may call repaint
   }

}

public class PreferenceCustomizer extends Dialog {
    public PreferenceCustomizer(PreferenceModal pm)
   {
        // create controls and populate it using get methods of    pm. also add handlers
   }

   public void actionPerformed (...)
  {
       // validate and if ok, call setMethods of pm
  }

}
   


// the main code in main method/init method

Grapher g = new Grapher();
PreferenceChanger pc = new PreferenceChanger(g);

// add these where ever you want





0
 

Author Comment

by:mbunkows
ID: 1223298
oh yeah that sounds logical

darn pretty too

Thanks alot

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 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…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

860 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