Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Event Issues

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Event Issues

    I'm writing a program (or should I say, I have written a program) that generates orbits from an Iterative Function System... but it has no GUI. Well, after a few months I've grown weary of that, so I decided to switch to netbeans and toss up a little GUI (window builder for eclipse... dreadful). The problem is, I need the JFrame (or a table component therein) to listen for an event. From a class that isn't event driven. I used to send a few lines of information per percent of completion, which I would like to land in the table component [that part I've figured out], and update that table every percent or tenth of a percent. Something like:

    IFS: "Hey! Another percent of 80 million points complete... could you let that fractal dude know?
    JFrame: Sure!

    I know I'll have to add an event listener to the component, and that I may have to write an event (I'd rather not if its avoidable). Concisely my query is how to fire off the event in a class with no GUI and have the JFrame.component 'hear' it.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Event Issues

    how to fire off the event in a class with no GUI and have the JFrame.component 'hear' it
    You could have the other class call a method in the GUI class when you want it to know of the event.
    To make it "type safe" you could define an interface containing the method to be called and the type of data to be passed and have the GUI class implement that interface. The method being called in the GUI class should act like any good listener, make a note of the event, copy needed data and return very quickly to the caller.

  3. The Following User Says Thank You to Norm For This Useful Post:

    fractalorbit (September 2nd, 2011)

  4. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Event Issues

    Thank you very much! That helps a lot. I'm not trying to plug myself here, but I have a lot of the output of my program here. Not that its pertinent to the problem (why I didn't have it in the initial post) but it may be interesting to someone The Fractal Rant. Though, it seems like with that approach I might not need to use an actual event. Am I mistaken? By calling the method in the GUI class, passing it a parameter that contains all the updated information, could I not reflect the update on the GUI without using the event system?

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Event Issues

    Your call would be very similar to the GUI class being called at one of its listener methods.

Similar Threads

  1. [SOLVED] jTable event help
    By banny7 in forum AWT / Java Swing
    Replies: 12
    Last Post: August 1st, 2011, 07:42 AM
  2. Event Handling
    By maress in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 24th, 2011, 03:29 AM
  3. After a rowInserted() event!
    By MarkusHendersonicus in forum JDBC & Databases
    Replies: 1
    Last Post: December 20th, 2010, 12:55 PM
  4. Menu Event Listeners
    By Gondee in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 16th, 2010, 03:08 PM
  5. Event handling
    By subhvi in forum AWT / Java Swing
    Replies: 3
    Last Post: August 26th, 2009, 11:20 AM