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 2 of 2

Thread: Custom Events

  1. #1
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,660
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Custom Events

    I am attempting to create a game with a small team of friends. I had the idea of taking advantage of Event-Driven programming to deal with User Interaction, and I wanted some words-of-wisdom from some of the people on this messageboard.

    First of all, we would be required to create a custom Event class and a custom EventListener class. The EventListener would probably be straightforward, but I'm not familiar with creating custom Events. Does anyone have any suggested reading material?

    Our current design incorporates an Android GUI, a Director class, the Event class, and a handful of sprites with different states. I would like an opinion on our design.
    The flow goes like this:
    1. The Director class has an EventListener attached to it.
    2. The user does something on the GUI. A custom Event is created with some sort of payload explaining what the Event was.
    3. The Event is sent to the Director, which hears the Event, changes the states of the sprites in some way, and notifies the GUI that the changes have been made (somehow).
    4. The GUI adjusts the images and information on the screen based on the new states of the sprites.

    Other than opinions on the design, how would we send the Director an Event in such a way that the EventListener would react to it? My main experience with Event-Driven programming is using Swing, but those Events are already created somehow and received by the component with the listener attached. I understand how to handle Events, just not how to create and send them.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,425
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Custom Events

    just not how to create
    Look at the Java SE doc for the different Events it has and model yours after them.

    Did you ask Google: create custom java event


    Also see the Observable class.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Events in Android
    By Nesh108 in forum Android Development
    Replies: 3
    Last Post: February 29th, 2012, 09:49 AM
  2. JButton events
    By pottsiex5 in forum AWT / Java Swing
    Replies: 9
    Last Post: September 27th, 2011, 12:57 PM
  3. [SOLVED] events log
    By nasi in forum Java Theory & Questions
    Replies: 1
    Last Post: May 17th, 2010, 05:21 AM
  4. JComboBoxes & Events
    By KevinGreen in forum AWT / Java Swing
    Replies: 3
    Last Post: April 21st, 2010, 05:11 AM
  5. Connecting events
    By Olufemi in forum AWT / Java Swing
    Replies: 0
    Last Post: April 21st, 2010, 04:58 AM