Hamlet is the one who exhibits a melancholy mood as the audience first sees him in the first act. The funeral for his father has been between one and two months since and he is still in great mourning for his loss. The time for which mourning should be spent is not only determined by the person who suffers the loss, but by the standards of the society in which s/he lives. Apparently for Hamlet's standards, a little more than a couple of months is deserving for a mournful period as opposed to his mother's attitude. She is the one who first asks Hamlet to put off his mourning and to continue life. Hamlet's response to his mother is declared with not only sadness, but a little bit of anger.
Hamlet shows his loyalty to his father by continuing in a melancholy state as opposed to his mother who seems happy and has also remarried. Speaking of "seems" that is exactly the word Gertrude uses to bring up the topic and Hamlet says that he's not just seeming to mourn, but he is mourning. He says that many people show their sadness after a funeral by wearing black clothes and crying a "fruitful river in the eye" (I.ii.83), but he is not just trying to show his sadness, he really is sad.
Claudius chimes in after Hamlet declares his support to his father by truly mourning:
It shows a will most incorrect to heaven,
A heart unfortified, a mind impatient,
An understanding simple and unschool'd;
For what we know must be, and is as common
As any the most vulgar thing to sense,
Why should we, in our peevish opposition,
Take it to heart? Fie! 'tis a fault to heaven,
A fault against the dead, a fault to nature,(I.ii.98-105).
Translation? By mourning too long, a man shows that he is weak and his behavior is disrespectful to heaven and to the one who died. Claudius even goes as far as to say that Hamlet's melancholy is "unmanly" (I.ii.97). Hamlet does not respond to Claudius until after he leaves the room with his mother and it's not good. He responds by saying that he's not buying into what they say and he thinks something is wrong with them and not with himself.