Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 770259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:28:13+00:00 2026-05-14T18:28:13+00:00

Observer pattern? Where do i get examples of this in Java (i know google

  • 0

Observer pattern? Where do i get examples of this in Java (i know google but was hoping for some personal insight also.)

On to a proper explanation of my issue:

i have 3 forms/windows. “board” is the main form that loads as the application.

“chat” is where the text chat takes place.

“network” is where network connection is established.

i have the game (connect4) working locally and i would like to implement a networked version of it also.

my idea is maybe it is related to Observer pattern to have a thread (or something) monitoring network state during runtime and update the chat and board forms of the current network status as well as delivering received data from the network.

are my ideas valid? or how should i go about establishing network and network status updates throughout the application?

thank you for your input.

board http://img39.imageshack.us/img39/5221/boardz.jpg

chat http://img691.imageshack.us/img691/3629/chatos.jpg

network http://img441.imageshack.us/img441/5906/networks.jpg

EDIT: is there a book on Java Observer pattern any one can recommend?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:28:14+00:00Added an answer on May 14, 2026 at 6:28 pm

    In this instance the chat and game windows would be considered Observers. You’ll want to implement an interface called something like Observers (the java API has a native Observer pattern at java.util.Observer but you can implement your own) and have your chat and board window implement them. You might have it look like:

    public interface Observer 
    {
    public void postUpdate(String newData); 
    }
    

    postUpdate is a function that all of the Observers will need to define, and both these classes and anything else you want to include later will need to implement Observer, like:

    public class ChatWindow Implements Observer
    {
    //bla bla bla
    }
    

    Then, in your network class, you’ll want a method like

    public void addObserver(Observer newObserver)
    {
    //Do something here to add the new Observer to some list of Observers, maybe a
    //List<Observer> or something?
    }
    

    Then, during initialization, you will want to want to call the addObserver function from each Observer you want to have watching it, and have some logic in your network class to update everybody who has registered by calling their postUpdate functions. In this case I acted as though you want to send them a String containing new data, that is only one option. You could also have it pass nothing and just act as notification that an update has occured in which case the Observers will be responsible for checking if the data they care about from the network has changed; or maybe you could have it pass some data representing what exactly has been updated on the network, such that the class could know if it cares about what has changed (for example, the gameboard might not care if the only change has occured to chat data, so it won’t bother doing anything else).

    You may find best success investigating Head First Design Patterns, in terms of books.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 422k
  • Answers 422k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just to complete this question. In my case the problem… May 15, 2026 at 11:24 am
  • Editorial Team
    Editorial Team added an answer The Installer class gives you a way to take get… May 15, 2026 at 11:24 am
  • Editorial Team
    Editorial Team added an answer I would have to say the best approach to this… May 15, 2026 at 11:24 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.