Solved

passing info from dialog

Posted on 1998-06-16
2
173 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
Comment Utility
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
Comment Utility
oh yeah that sounds logical

darn pretty too

Thanks alot

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

762 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

6 Experts available now in Live!

Get 1:1 Help Now