Before the play begins, Hamlet's father is poisoned--murdered. The murdered king's spirit then visits and makes Hamlet aware of the details of his death, in hopes that Hamlet will avenge his death.
Hamlet is perhaps the most rich of Shakespeare's tragedies, orchestrating an incredible array of characters into shocking and sometimes surprisingly realistic situations.
Before the play even begins there is quite a bit of action that takes place, this includes the murder of Hamlet's father, the King of Denmark. Spoiler Alert: Claudius did it by poisoning him. (What ever happened to family first?) At the beginning of the play an apparition of the dead king appears to Hamlet, telling him exactly what has happened and demanding that he take revenge against his uncle, the new king. Claudius, a brilliant politician and exceedingly bright man, swoops on the throne and marries Hamlet's mother, Gertrude. No one can really understand why she would do such a thing, but it seems to be implied that she may have been having an affair with Claudius even before her husband's murder, she is frequently described as weak and innocent.
The ghost's appearance to Hamlet is rather traumatic and sets Hamlet up for some real personal struggles that eventually lead to just about everyone in the play's death. These personal struggles lead to one of the biggest literary debates of all time, concerning the madness of Hamlet. Was he, or wasn't he insane? It's really up to one's own interpretation, but as far as I can tell, he was sane, just troubled, which is incredibly understandable because his father was murdered by his uncle. It is questionable as to the appearance of the ghost itself, as it could be a delusion, but it would seem that this character is just a catalyst for information that Shakespeare needed to convey.