Solved

passing info from dialog

Posted on 1998-06-16
2
175 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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 last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

813 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

14 Experts available now in Live!

Get 1:1 Help Now