?
Solved

passing info from dialog

Posted on 1998-06-16
2
Medium Priority
?
180 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
[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 Comments
 
LVL 4

Accepted Solution

by:
evijay earned 400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
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 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:
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 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